ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/item.C
Revision: 1.65
Committed: Sat Nov 7 18:30:05 2009 UTC (14 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.64: +1 -1 lines
Log Message:
lots of cleanups

File Contents

# User Rev Content
1 elmex 1.1 /*
2 root 1.41 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 pippijn 1.19 *
4 root 1.53 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 root 1.36 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6     * Copyright (©) 1992,2007 Frank Tore Johansen
7 pippijn 1.19 *
8 root 1.58 * Deliantra is free software: you can redistribute it and/or modify it under
9     * the terms of the Affero GNU General Public License as published by the
10     * Free Software Foundation, either version 3 of the License, or (at your
11     * option) any later version.
12 pippijn 1.19 *
13 root 1.38 * This program is distributed in the hope that it will be useful,
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     * GNU General Public License for more details.
17 pippijn 1.19 *
18 root 1.58 * You should have received a copy of the Affero GNU General Public License
19     * and the GNU General Public License along with this program. If not, see
20     * <http://www.gnu.org/licenses/>.
21 root 1.36 *
22 root 1.41 * The authors can be reached via e-mail to <support@deliantra.net>
23 pippijn 1.19 */
24 elmex 1.1
25     #include <global.h>
26     #include <living.h>
27     #include <spells.h>
28    
29 root 1.42 const char *const coins[NUM_COINS + 1] = { "royalty", "platinacoin", "goldcoin", "silvercoin", 0 };
30    
31 elmex 1.1 /* the ordering of this is actually doesn't make a difference
32     * However, for ease of use, new entries should go at the end
33     * so those people that debug the code that get used to something
34     * being in the location 4 don't get confused.
35     *
36     * The ordering in save_name, use_name, nonuse_name.
37     * save_name is the name used to load/save it from files. It should
38     * match that of the doc/Developers/objects. The only
39     * real limitation is that it shouldn't have spaces or other characters
40     * that may mess up the match code. It must also start with body_
41     * use_name is how we describe the location if we can use it.
42     * nonuse_name is how we describe it if we can't use it. I think
43     * the values below will make it pretty clear how those work out
44     * They are basically there to make life a little easier - if a character
45     * examines an item and it says it goes on 'your arm', its pretty clear
46     * they can use it. See the last sample (commented out) for a dragon
47     * Note that using the term 'human' may not be very accurate, humanoid
48     * may be better.
49     * Basically, for the use/nonuse, the code does something like:
50     * "This item goes %s\n", with the use/nonuse values filling in the %s
51     */
52     Body_Locations body_locations[NUM_BODY_LOCATIONS] = {
53 root 1.35 {KW_body_skill , "You can use it as your skill" , "It is used as a skill"},
54     {KW_body_combat , "You can wield it as your weapon" , "It is used as a combat weapon"},
55     {KW_body_range , "You can use it as your range weapon" , "It is used as a range weapon"},
56     {KW_body_shield , "You can wield it as a shield" , "It is used as a shield"},
57     {KW_body_arm , "You can put it on your arm" , "It goes on a human's arm"},
58     {KW_body_torso , "You can wear it on your body" , "It goes on a human's torso"},
59     {KW_body_head , "You can wear it on your head" , "It goes on a human's head"},
60     {KW_body_neck , "You can wear it around your neck" , "It goes around a human's neck"},
61     {KW_body_finger , "You can wear it on your finger" , "It goes on a human's finger"} ,
62     {KW_body_shoulder, "You can wear it around your shoulders", "It goes around a human's shoulders"},
63     {KW_body_foot , "You can put it on your foot" , "It goes on a human's foot"},
64     {KW_body_hand , "You can put it on your hand" , "It goes on a human's hand"},
65     {KW_body_wrist , "You can wear it around your wrist" , "It goes around a human's wrist"},
66     {KW_body_waist , "You can wear it around your waist" , "It goes around a human's waist"},
67 elmex 1.1 /*{"body_dragon_torso", "your body", "a dragon's body"} */
68     };
69    
70     static char numbers_10[10][20] = {
71 root 1.4 "zero", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy",
72     "eighty", "ninety"
73 elmex 1.1 };
74    
75     static char levelnumbers[21][20] = {
76 root 1.4 "zeroth", "first", "second", "third", "fourth", "fifth", "sixth", "seventh",
77 elmex 1.1 "eighth", "ninth", "tenth", "eleventh", "twelfth", "thirteenth",
78     "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteen",
79     "nineteen", "twentieth"
80     };
81    
82     static char levelnumbers_10[11][20] = {
83 root 1.4 "zeroth", "tenth", "twentieth", "thirtieth", "fortieth", "fiftieth", "sixtieth",
84     "seventieth", "eightieth", "ninetieth"
85 elmex 1.1 };
86    
87     /* The following is a large table of item types, the fields are:
88     * item number, item name, item name (plural), and two numbers that are the skills
89     * used to identify them. Anytime a new item type is added or removed, this list
90     * should be altered to reflect that. The defines for the numerical values are in
91     * define.h
92     */
93     static const typedata item_types[] = {
94 root 1.4 {PLAYER, "player", "players", 0, 0},
95     {ROD, "rod", "rods", SK_THAUMATURGY, 0},
96     {TREASURE, "treasure", "treasure", 0, 0},
97     {POTION, "potion", "potions", SK_ALCHEMY, 0},
98     {FOOD, "food", "food", SK_WOODSMAN, 0},
99     {POISON, "poison", "poisons", SK_ALCHEMY, 0},
100     {BOOK, "book", "books", SK_LITERACY, 0},
101     {CLOCK, "clock", "clocks", 0, 0},
102     {ARROW, "arrow", "arrows", SK_BOWYER, 0},
103     {BOW, "bow", "bows", SK_BOWYER, 0},
104     {WEAPON, "weapon", "weapons", SK_SMITHERY, 0},
105     {ARMOUR, "armour", "armour", SK_SMITHERY, 0},
106     {PEDESTAL, "pedestal", "pedestals", 0, 0},
107     {ALTAR, "altar", "altars", 0, 0},
108     {LOCKED_DOOR, "locked door", "locked doors", 0, 0},
109     {SPECIAL_KEY, "special key", "special keys", 0, 0},
110     {MAP, "map", "maps", 0, 0},
111     {DOOR, "door", "doors", 0, 0},
112     {KEY, "key", "keys", 0, 0},
113     {TIMED_GATE, "timed_gate", "timed_gates", 0, 0},
114     {TRIGGER, "trigger", "triggers", 0, 0},
115     {GRIMREAPER, "grimreaper", "grimreapers", 0, 0},
116     {MAGIC_EAR, "magic ear", "magic ears", 0, 0},
117     {TRIGGER_BUTTON, "trigger button", "trigger buttons", 0, 0},
118     {TRIGGER_ALTAR, "trigger altar", "trigger altars", 0, 0},
119     {TRIGGER_PEDESTAL, "trigger pedestal", "trigger pedestals", 0, 0},
120     {SHIELD, "shield", "shields", SK_SMITHERY, 0},
121     {HELMET, "helmet", "helmets", SK_SMITHERY, 0},
122     {HORN, "horn", "horns", SK_THAUMATURGY, 0},
123     {MONEY, "money", "money", 0, 0},
124     {CLASS, "class", "classes", 0, 0},
125     {GRAVESTONE, "gravestone", "gravestones", 0, 0},
126     {AMULET, "amulet", "amulets", SK_JEWELER, 0},
127     {PLAYERMOVER, "player mover", "player movers", 0, 0},
128     {TELEPORTER, "teleporter", "teleporters", 0, 0},
129     {CREATOR, "creator", "creators", 0, 0},
130     {SKILL, "skill", "skills", 0, 0},
131     {EARTHWALL, "earthwall", "earthwalls", 0, 0},
132     {GOLEM, "golem", "golems", 0, 0},
133     {THROWN_OBJ, "projectile", "projectiles", 0, 0},
134     {BLINDNESS, "blindness", "blindness", 0, 0},
135     {GOD, "god", "gods", 0, 0},
136     {DETECTOR, "detector", "detectors", 0, 0},
137     {TRIGGER_MARKER, "trigger marker", "trigger markers", 0, 0},
138     {DEAD_OBJECT, "dead object", "dead objects", 0, 0},
139     {DRINK, "drink", "drinks", SK_WOODSMAN, SK_ALCHEMY},
140     {MARKER, "marker", "markers", 0, 0},
141     {HOLY_ALTAR, "holy altar", "holy altars", 0, 0},
142     {PLAYER_CHANGER, "player changer", "player changers", 0, 0},
143     {BATTLEGROUND, "battleground", "battlegrounds", 0, 0},
144     {PEACEMAKER, "peacemaker", "peacemakers", 0, 0},
145     {GEM, "gem", "gems", SK_JEWELER, 0},
146     {FIREWALL, "firewall", "firewalls", 0, 0},
147     {ANVIL, "anvil", "anvils", 0, 0},
148     {CHECK_INV, "inventory checker", "inventory checkers", 0, 0},
149     {MOOD_FLOOR, "mood floor", "mood floors", 0, 0},
150     {EXIT, "exit", "exits", 0, 0},
151     {ENCOUNTER, "encounter", "encounters", 0, 0},
152     {SHOP_FLOOR, "shop floor", "shop floors", 0, 0},
153     {SHOP_MAT, "shop mat", "shop mats", 0, 0},
154     {RING, "ring", "rings", SK_JEWELER, 0},
155     {FLOOR, "floor", "floors", 0, 0},
156     {FLESH, "flesh", "flesh", SK_WOODSMAN, 0},
157     {INORGANIC, "inorganic", "inorganics", SK_ALCHEMY, 0},
158     {SKILL_TOOL, "skill tool", "skill tools", 0, 0},
159     {LIGHTER, "lighter", "lighters", 0, 0},
160 elmex 1.12 {BUILDABLE_WALL, "buildable wall", "buildable walls", 0, 0},
161 root 1.4 {MISC_OBJECT, "bric-a-brac", "bric-a-brac", 0, 0},
162     {LAMP, "lamp", "lamps", 0, 0},
163     {DUPLICATOR, "duplicator", "duplicators", 0, 0},
164     {SPELLBOOK, "spellbook", "spellbooks", SK_LITERACY, 0},
165     {CLOAK, "cloak", "cloaks", SK_SMITHERY, 0},
166     {SPINNER, "spinner", "spinners", 0, 0},
167     {GATE, "gate", "gates", 0, 0},
168     {BUTTON, "button", "buttons", 0, 0},
169 root 1.59 {T_HANDLE, "cf handle", "cf handles", 0, 0},
170 root 1.4 {HOLE, "hole", "holes", 0, 0},
171     {TRAPDOOR, "trapdoor", "trapdoors", 0, 0},
172     {SIGN, "sign", "signs", 0, 0},
173     {BOOTS, "boots", "boots", SK_SMITHERY, 0},
174     {GLOVES, "gloves", "gloves", SK_SMITHERY, 0},
175     {SPELL, "spell", "spells", 0, 0},
176     {SPELL_EFFECT, "spell effect", "spell effects", 0, 0},
177     {CONVERTER, "converter", "converters", 0, 0},
178     {BRACERS, "bracers", "bracers", SK_SMITHERY, 0},
179     {POISONING, "poisoning", "poisonings", 0, 0},
180     {SAVEBED, "savebed", "savebeds", 0, 0},
181     {WAND, "wand", "wands", SK_THAUMATURGY, 0},
182     {SCROLL, "scroll", "scrolls", SK_LITERACY, 0},
183     {DIRECTOR, "director", "directors", 0, 0},
184     {GIRDLE, "girdle", "girdles", SK_SMITHERY, 0},
185     {FORCE, "force", "forces", 0, 0},
186     {POTION_EFFECT, "potion effect", "potion effects", 0, 0},
187     {CLOSE_CON, "closed container", "closed container", 0, 0},
188     {CONTAINER, "container", "containers", SK_ALCHEMY, 0},
189     {ARMOUR_IMPROVER, "armour improver", "armour improvers", 0, 0},
190     {WEAPON_IMPROVER, "weapon improver", "weapon improvers", 0, 0},
191     {SKILLSCROLL, "skillscroll", "skillscrolls", 0, 0},
192     {DEEP_SWAMP, "deep swamp", "deep swamps", 0, 0},
193     {IDENTIFY_ALTAR, "identify altar", "identify altars", 0, 0},
194     {MENU, "inventory list", "inventory lists", 0, 0},
195     {RUNE, "rune", "runes", 0, 0},
196     {TRAP, "trap", "traps", 0, 0},
197     {POWER_CRYSTAL, "power_crystal", "power_crystals", 0, 0},
198     {CORPSE, "corpse", "corpses", 0, 0},
199     {DISEASE, "disease", "diseases", 0, 0},
200     {SYMPTOM, "symptom", "symptoms", 0, 0},
201     {BUILDER, "item builder", "item builders", 0, 0},
202     {MATERIAL, "building material", "building materials", 0, 0},
203     {ITEM_TRANSFORMER, "item_transformer", "item_transformers", 0, 0},
204 elmex 1.1 };
205    
206 root 1.63 static const int item_types_size = sizeof (item_types) / sizeof (*item_types);
207 elmex 1.1
208     materialtype_t *materialt;
209    
210     /*
211     materialtype material[NROFMATERIALS] = {
212     * P M F E C C A D W G P S P T F C D D C C G H B I *
213     * H A I L O O C R E H O L A U E A E E H O O O L N *
214     * Y G R E L N I A A O I O R R A N P A A U D L I T *
215     * S I E C D F D I P S S W A N R C L T O N Y N R *
216     * I C T U N O T O L E E H S T P D N *
217     {"paper", {15,10,17, 9, 5, 7,13, 0,20,15, 0,0,0,0,0,10,0,0,0,0,0,0,0,0}},
218     {"metal", { 2,12, 3,12, 2,10, 7, 0,20,15, 0,0,0,0,0,10,0,0,0,0,0,0,0,0}},
219     {"glass", {14,11, 8, 3,10, 5, 1, 0,20,15, 0,0,0,0,0, 0,0,0,0,0,0,0,0,0}},
220     {"leather", { 5,10,10, 3, 3,10,10, 0,20,15, 0,0,0,0,0,12,0,0,0,0,0,0,0,0}},
221     {"wood", {10,11,13, 2, 2,10, 9, 0,20,15, 0,0,0,0,0,12,0,0,0,0,0,0,0,0}},
222     {"organics", { 3,12, 9,11, 3,10, 9, 0,20,15, 0,0,0,0,0, 0,0,0,0,0,0,0,0,0}},
223     {"stone", { 2, 5, 2, 2, 2, 2, 1, 0,20,15, 0,0,0,0,0, 5,0,0,0,0,0,0,0,0}},
224     {"cloth", {14,11,13, 4, 4, 5,10, 0,20,15, 0,0,0,0,0, 5,0,0,0,0,0,0,0,0}},
225     {"adamant", { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0, 0,0,0,0,0,0,0,0,0}},
226     {"liquid", { 0, 8, 9, 6,17, 0,15, 0,20,15,12,0,0,0,0,11,0,0,0,0,0,0,0,0}},
227     {"soft metal",{ 6,12, 6,14, 2,10, 1, 0,20,15, 0,0,0,0,0,10,0,0,0,0,0,0,0,0}},
228     {"bone", {10, 9, 4, 5, 3,10,10, 0,20,15, 0,0,0,0,0, 2,0,0,0,0,0,0,0,0}},
229     {"ice", {14,11,16, 5, 0, 5, 6, 0,20,15, 0,0,0,0,0, 7,0,0,0,0,0,0,0,0}}
230     };
231     */
232    
233     /* This curve may be too steep. But the point is that there should
234     * be tough choices - there is no real point to this if everyone can
235     * wear whatever they want with no worries. Perhaps having the steep
236     * curve is good (maybe even steeper), but allowing players to
237     * have 2 * level instead. Ideally, top level characters should only be
238     * able to use 2-3 of the most powerful items.
239     * note that this table is only really used for program generated items -
240     * custom objects can use whatever they want.
241     */
242     static int enc_to_item_power[21] = {
243 root 1.4 0, 0, 1, 2, 3, 4, /* 5 */
244     5, 7, 9, 11, 13, /* 10 */
245     15, 18, 21, 24, 27, /* 15 */
246     30, 35, 40, 45, 50 /* 20 */
247 elmex 1.1 };
248    
249 root 1.4 int
250     get_power_from_ench (int ench)
251 elmex 1.1 {
252 root 1.53 return enc_to_item_power [clamp (ench, 0, 20)];
253 elmex 1.1 }
254    
255     /* This takes an object 'op' and figures out what its item_power
256     * rating should be. This should only really be used by the treasure
257     * generation code, and when loading legacy objects. It returns
258     * the item_power it calculates.
259     * If flag is 1, we return the number of enchantment, and not the
260     * the power. This is used in the treasure code.
261     */
262 root 1.4 int
263     calc_item_power (const object *op, int flag)
264 elmex 1.1 {
265 root 1.4 int i, tmp, enc;
266 elmex 1.1
267 root 1.4 enc = 0;
268     for (i = 0; i < NUM_STATS; i++)
269 root 1.33 enc += op->stats.stat (i);
270 root 1.4
271     /* This protection logic is pretty flawed. 20% fire resistance
272     * is much more valuable than 20% confusion, or 20% slow, or
273     * several others. Start at 1 - ignore physical - all that normal
274     * armour shouldn't be counted against
275     */
276     tmp = 0;
277     for (i = 1; i < NROFATTACKS; i++)
278     tmp += op->resist[i];
279    
280     /* Add/substract 10 so that the rounding works out right */
281     if (tmp > 0)
282     enc += (tmp + 10) / 20;
283     else if (tmp < 0)
284     enc += (tmp - 10) / 20;
285    
286     enc += op->magic;
287    
288     /* For each attacktype a weapon has, one more encantment. Start at 1 -
289     * physical doesn't count against total.
290     */
291     if (op->type == WEAPON)
292     {
293     for (i = 1; i < NROFATTACKS; i++)
294     if (op->attacktype & (1 << i))
295     enc++;
296 root 1.49
297 root 1.4 if (op->slaying)
298     enc += 2; /* What it slays is probably more relevent */
299     }
300 root 1.49
301 root 1.4 /* Items the player can equip */
302     if ((op->type == WEAPON) || (op->type == ARMOUR) || (op->type == HELMET) ||
303     (op->type == SHIELD) || (op->type == RING) ||
304     (op->type == BOOTS) || (op->type == GLOVES) ||
305     (op->type == AMULET) || (op->type == GIRDLE) || (op->type == BRACERS) || (op->type == CLOAK))
306     {
307     enc += op->stats.food; /* sustenance */
308     enc += op->stats.hp; /* hp regen */
309     enc += op->stats.sp; /* mana regen */
310     enc += op->stats.grace; /* grace regen */
311     enc += op->stats.exp; /* speed bonus */
312     }
313 root 1.49
314 root 1.4 enc += op->stats.luck;
315    
316     /* Do spell paths now */
317     for (i = 1; i < NRSPELLPATHS; i++)
318     {
319     if (op->path_attuned & (1 << i))
320     enc++;
321     else if (op->path_denied & (1 << i))
322     enc -= 2;
323     else if (op->path_repelled & (1 << i))
324     enc--;
325     }
326    
327 root 1.55 if (op->flag [FLAG_LIFESAVE ]) enc += 5;
328     if (op->flag [FLAG_REFL_SPELL ]) enc += 3;
329     if (op->flag [FLAG_REFL_MISSILE]) enc += 2;
330     if (op->flag [FLAG_XRAYS ]) enc += 2;
331     if (op->flag [FLAG_STEALTH ]) enc += 1;
332     if (op->flag [FLAG_SEE_IN_DARK ]) enc += 1;
333     if (op->flag [FLAG_MAKE_INVIS ]) enc += 1;
334 elmex 1.1
335 root 1.4 return get_power_from_ench (enc);
336 elmex 1.1 }
337    
338     /* returns the typedata that has a number equal to itemtype, if there
339     * isn't one, returns NULL */
340 root 1.4 const typedata *
341     get_typedata (int itemtype)
342     {
343 root 1.55 for (int i = 0; i < item_types_size; i++)
344 root 1.4 if (item_types[i].number == itemtype)
345     return &item_types[i];
346 root 1.49
347 root 1.4 return NULL;
348 elmex 1.1 }
349    
350     /* returns the typedata that has a name equal to itemtype, if there
351     * isn't one, return the plural name that matches, if there still isn't
352     * one return NULL */
353 root 1.4 const typedata *
354     get_typedata_by_name (const char *name)
355     {
356 root 1.55 for (int i = 0; i < item_types_size; i++)
357 root 1.4 if (!strcmp (item_types[i].name, name))
358     return &item_types[i];
359 root 1.49
360 root 1.55 for (int i = 0; i < item_types_size; i++)
361 root 1.4 if (!strcmp (item_types[i].name_pl, name))
362     {
363     LOG (llevInfo,
364 root 1.49 "get_typedata_by_name: I have been sent the plural %s, the singular form %s is prefered\n", name, item_types[i].name);
365 root 1.4 return &item_types[i];
366     }
367 root 1.49
368 root 1.55 return 0;
369 elmex 1.1 }
370 root 1.4
371 elmex 1.1 /* describe_resistance generates the visible naming for resistances.
372     * returns a static array of the description. This can return
373     * a big buffer.
374     * if newline is true, we don't put parens around the description
375     * but do put a newline at the end. Useful when dumping to files
376     */
377 root 1.25 const char *
378 root 1.4 describe_resistance (const object *op, int newline)
379 elmex 1.1 {
380 root 1.60 static dynbuf_text buf; buf.clear ();
381 root 1.4
382 root 1.60 for (int i = 0; i < NROFATTACKS; i++)
383     if (op->resist[i] && (op->type != FLESH || atnr_is_dragon_enabled (i) == 1))
384     buf.printf (newline ? "%s %d\n" : "(%s %+d)", resist_plus[i], op->resist[i]);
385 root 1.55
386 root 1.4 return buf;
387 elmex 1.1 }
388    
389     /*
390     * query_weight(object) returns a character pointer to a static buffer
391     * containing the text-representation of the weight of the given object.
392     * The buffer will be overwritten by the next call to query_weight().
393 root 1.55 *
394     * Seems to be used only by unimportant stuff. Remove?
395 elmex 1.1 */
396 root 1.25 const char *
397 root 1.4 query_weight (const object *op)
398     {
399 elmex 1.1 static char buf[10];
400 root 1.46 sint32 i = op->total_weight ();
401 elmex 1.1
402 root 1.4 if (op->weight < 0)
403 elmex 1.1 return " ";
404 root 1.25
405 root 1.4 if (i % 1000)
406     sprintf (buf, "%6.1f", i / 1000.0);
407 elmex 1.1 else
408 root 1.4 sprintf (buf, "%4d ", i / 1000);
409 root 1.25
410 elmex 1.1 return buf;
411     }
412    
413     /*
414     * Returns the pointer to a static buffer containing
415     * the number requested (of the form first, second, third...)
416     */
417 root 1.25 const char *
418 root 1.4 get_levelnumber (int i)
419     {
420 elmex 1.1 static char buf[MAX_BUF];
421 root 1.4
422     if (i > 99)
423     {
424     sprintf (buf, "%d.", i);
425     return buf;
426     }
427 root 1.25
428 root 1.4 if (i < 21)
429 elmex 1.1 return levelnumbers[i];
430 root 1.55
431 root 1.4 if (!(i % 10))
432     return levelnumbers_10[i / 10];
433 root 1.25
434 root 1.4 strcpy (buf, numbers_10[i / 10]);
435     strcat (buf, levelnumbers[i % 10]);
436 elmex 1.1 return buf;
437     }
438    
439     /*
440     * Returns pointer to static buffer containing ring's or amulet's
441     * abilities
442     * These are taken from old query_name(), but it would work better
443     * if describle_item() would be called to get this information and
444     * caller would handle FULL_RING_DESCRIPTION definition.
445     * Or make FULL_RING_DESCRIPTION standard part of a game and let
446     * client handle names.
447     */
448 root 1.4
449 elmex 1.1 /* Aug 95 modified this slightly so that Skill tools don't have magic bonus
450     * from stats.sp - b.t.
451     */
452 root 1.63 static const char *
453 root 1.4 ring_desc (const object *op)
454 elmex 1.1 {
455 root 1.39 static dynbuf_text buf; buf.clear ();
456 root 1.4 int attr, val, len;
457 elmex 1.1
458 root 1.39 if (QUERY_FLAG (op, FLAG_IDENTIFIED))
459     {
460     for (attr = 0; attr < NUM_STATS; attr++)
461     if ((val = op->stats.stat (attr)))
462     buf.printf ("(%s%+d)", short_stat_name[attr], val);
463 elmex 1.1
464 root 1.39 if (op->stats.exp) buf.printf ("(speed %+lld)", (long long)op->stats.exp);
465     if (op->stats.wc) buf.printf ("(wc%+d)", op->stats.wc);
466     if (op->stats.dam) buf.printf ("(dam%+d)", op->stats.dam);
467     if (op->stats.ac) buf.printf ("(ac%+d)", op->stats.ac);
468    
469     buf << describe_resistance (op, 0);
470    
471     if (op->stats.food) buf.printf ("(sustenance%+d)", op->stats.food);
472     if (op->stats.grace) buf.printf ("(grace%+d)", op->stats.grace);
473     if (op->stats.sp && op->type != SKILL) buf.printf ("(magic%+d)", op->stats.sp);
474     if (op->stats.hp) buf.printf ("(regeneration%+d)", op->stats.hp);
475     if (op->stats.luck) buf.printf ("(luck%+d)", op->stats.luck);
476    
477     if (QUERY_FLAG (op, FLAG_LIFESAVE)) buf << "(lifesaving)";
478     if (QUERY_FLAG (op, FLAG_REFL_SPELL)) buf << "(reflect spells)";
479     if (QUERY_FLAG (op, FLAG_REFL_MISSILE)) buf << "(reflect missiles)";
480     if (QUERY_FLAG (op, FLAG_STEALTH)) buf << "(stealth)";
481    
482     buf.add_paths ("Attuned" , op->path_attuned);
483     buf.add_paths ("Repelled", op->path_repelled);
484     buf.add_paths ("Denied" , op->path_denied);
485 root 1.4
486 root 1.39 if (buf.empty ())
487     buf << "of adornment";
488 root 1.4 }
489 root 1.27
490 root 1.4 return buf;
491 elmex 1.1 }
492    
493     /*
494     * query_short_name(object) is similar to query_name, but doesn't
495     * contain any information about object status (worn/cursed/etc.)
496 root 1.55 *
497     * It is sometimes used when printing messages, so should fit well into a sentence.
498 elmex 1.1 */
499 root 1.4 const char *
500     query_short_name (const object *op)
501 elmex 1.1 {
502 root 1.52 if (!op->name)
503 root 1.4 return "(null)";
504 root 1.5
505 root 1.42 if (!op->nrof
506     && !op->weight
507     && !op->title
508     && !is_magical (op)
509     && op->slaying != shstr_money)
510 root 1.4 return op->name; /* To speed things up (or make things slower?) */
511    
512 root 1.42 static dynbuf_text buf; buf.clear ();
513    
514 root 1.39 buf << (op->nrof <= 1 ? op->name : op->name_pl);
515 root 1.4
516     if (op->title && QUERY_FLAG (op, FLAG_IDENTIFIED))
517 root 1.39 buf << ' ' << op->title;
518 elmex 1.1
519 root 1.4 switch (op->type)
520     {
521 root 1.39 case SPELLBOOK:
522     case SCROLL:
523     case WAND:
524     case ROD:
525     if (QUERY_FLAG (op, FLAG_IDENTIFIED) || QUERY_FLAG (op, FLAG_BEEN_APPLIED))
526     {
527     if (!op->title)
528     buf << " of " << (op->inv ? &op->inv->name : "bug, please report");
529    
530     if (op->type != SPELLBOOK)
531     buf.printf (" (lvl %d)", op->level);
532     }
533     break;
534    
535 root 1.53 case ALTAR:
536     case TRIGGER_ALTAR:
537     case IDENTIFY_ALTAR:
538     case CONVERTER:
539     if (op->slaying == shstr_money)
540     {
541     bool wrap = !!buf.size ();
542 root 1.42
543 root 1.53 if (wrap) buf << " [";
544 root 1.42
545 root 1.53 archetype *coin = 0;
546 root 1.42
547 root 1.53 for (char const *const *c = coins; *coins; ++c)
548     if ((coin = archetype::find (*c)))
549     if (op->stats.food % coin->value == 0)
550     break;
551 root 1.42
552 root 1.53 sint32 coins = op->stats.food / coin->value;
553 root 1.42
554 root 1.53 buf.printf ("drop %d %s (or equivalent)", coins, coins == 1 ? &coin->name : &coin->name_pl);
555 root 1.42
556 root 1.53 if (wrap) buf << ']';
557     }
558     break;
559 root 1.42
560 root 1.39 case SKILL:
561     case AMULET:
562     case RING:
563     if (!op->title)
564     {
565     /* If ring has a title, full description isn't so useful */
566     const char *s = ring_desc (op);
567 elmex 1.1
568 root 1.39 if (s && *s)
569     buf << " " << s;
570     }
571     break;
572 root 1.42
573 root 1.39 default:
574     if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED)))
575     buf.printf (" %+d", op->magic);
576 elmex 1.1 }
577 root 1.39
578 root 1.4 return buf;
579 elmex 1.1 }
580    
581     /*
582     * query_name(object) returns a character pointer pointing to a static
583     * buffer which contains a verbose textual representation of the name
584     * of the given object.
585     * cf 0.92.6: Put in 5 buffers that it will cycle through. In this way,
586     * you can make several calls to query_name before the bufs start getting
587     * overwritten. This may be a bad thing (it may be easier to assume the value
588     * returned is good forever.) However, it makes printing statements that
589     * use several names much easier (don't need to store them to temp variables.)
590     *
591 root 1.55 * It is used extensively within messages, so should return only a prose
592     * and short description of the item.
593 elmex 1.1 */
594 root 1.25 const char *
595 root 1.4 query_name (const object *op)
596     {
597 root 1.39 int len = 0;
598     static dynbuf_text bufs[5];
599 root 1.4 static int use_buf = 0;
600 elmex 1.1
601 root 1.4 use_buf++;
602     use_buf %= 5;
603 elmex 1.1
604 root 1.39 dynbuf_text &buf = bufs [use_buf];
605     buf.clear ();
606    
607 root 1.8 if ((op->is_armor () || op->is_weapon ()) && op->materialname)
608 root 1.39 if (materialtype_t *mt = name_to_material (op->materialname))
609     buf << mt->description << ' ';
610 elmex 1.1
611 root 1.39 buf << query_short_name (op);
612 elmex 1.1
613 root 1.4 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
614 root 1.39 buf << " *";
615 root 1.61 if (op->is_open_container ())
616 root 1.39 buf << " (open)";
617 root 1.4
618     if (QUERY_FLAG (op, FLAG_KNOWN_CURSED))
619     {
620     if (QUERY_FLAG (op, FLAG_DAMNED))
621 root 1.39 buf << " (damned)";
622 root 1.4 else if (QUERY_FLAG (op, FLAG_CURSED))
623 root 1.39 buf << " (cursed)";
624 root 1.4 }
625 root 1.23
626 root 1.4 /* Basically, if the object is known magical (detect magic spell on it),
627     * and it isn't identified, print out the fact that
628     * it is magical. Assume that the detect magical spell will only set
629     * KNOWN_MAGICAL if the item actually is magical.
630     *
631     * Changed in V 0.91.4 - still print that the object is magical even
632     * if it has been applied. Equipping an item does not tell full
633     * abilities, especially for artifact items.
634     */
635     if (QUERY_FLAG (op, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (op, FLAG_IDENTIFIED))
636 root 1.39 buf << " (magic)";
637 elmex 1.1
638     #if 0
639 root 1.55 /* item_power will be returned in describe_item - it shouldn't really
640 root 1.4 * be returned in the name.
641     */
642     if (op->item_power)
643     sprintf (buf[use_buf] + strlen (buf[use_buf]), "(item_power %+d)", op->item_power);
644 elmex 1.1
645     #endif
646    
647 root 1.4 if (QUERY_FLAG (op, FLAG_APPLIED))
648     {
649     switch (op->type)
650     {
651 root 1.23 case BOW:
652     case WAND:
653     case ROD:
654     case HORN:
655 root 1.39 buf << (op->env && op->env->current_weapon == op ? " (readied)" : " (applied)");
656 root 1.23 break;
657     case WEAPON:
658 root 1.39 buf << (op->env && op->env->current_weapon == op ? " (wielded)" : " (applied)");
659 root 1.23 break;
660     case ARMOUR:
661     case HELMET:
662     case SHIELD:
663     case RING:
664     case BOOTS:
665     case GLOVES:
666     case AMULET:
667     case GIRDLE:
668     case BRACERS:
669     case CLOAK:
670 root 1.39 buf << " (worn)";
671 root 1.23 break;
672     case CONTAINER:
673 root 1.39 buf << " (active)";
674 root 1.23 break;
675     case SKILL:
676     default:
677 root 1.39 buf << " (applied)";
678 root 1.2 }
679 elmex 1.1 }
680 root 1.23
681 elmex 1.54 switch (op->type)
682     {
683     case LAMP:
684     if (op->glow_radius)
685     buf << " (on)";
686     else if (op->stats.food <= 0)
687     buf << " (empty)";
688     else
689     buf << " (off)";
690     break;
691    
692     case TORCH:
693     if (op->glow_radius)
694     buf << " (burning)";
695     else if (op->stats.food <= 0)
696     buf << " (burned out)";
697     break;
698     }
699    
700 root 1.4 if (QUERY_FLAG (op, FLAG_UNPAID))
701 root 1.39 buf << " (unpaid)";
702 elmex 1.1
703 root 1.39 return buf;
704 elmex 1.1 }
705    
706     /*
707     * query_base_name(object) returns a character pointer pointing to a static
708     * buffer which contains a verbose textual representation of the name
709     * of the given object. The buffer will be overwritten at the next
710     * call to query_base_name(). This is a lot like query_name, but we
711     * don't include the item count or item status. Used for inventory sorting
712     * and sending to client.
713     * If plural is set, we generate the plural name of this.
714 root 1.55 *
715     * It is sometimes used to display messages, and usually only used to match stuff,
716     * so maybe this function should be removed.
717 elmex 1.1 */
718 root 1.4 const char *
719     query_base_name (const object *op, int plural)
720     {
721     if ((!plural && !op->name) || (plural && !op->name_pl))
722     return "(null)";
723 elmex 1.1
724 root 1.4 if (!op->nrof && !op->weight && !op->title && !is_magical (op))
725     return op->name; /* To speed things up (or make things slower?) */
726 elmex 1.1
727 root 1.39 static dynbuf_text buf; buf.clear ();
728    
729 root 1.8 if ((op->is_armor () || op->is_weapon ()) && op->materialname)
730 root 1.39 if (materialtype_t *mt = name_to_material (op->materialname))
731     if (op->arch->materialname != mt->name)
732     buf << mt->description << ' ';
733 root 1.20
734 root 1.39 buf << (plural ? op->name_pl : op->name);
735 elmex 1.1
736 root 1.4 if (op->title && QUERY_FLAG (op, FLAG_IDENTIFIED))
737 root 1.39 buf << ' ' << op->title;
738 elmex 1.1
739 root 1.4 switch (op->type)
740     {
741 root 1.20 case SPELLBOOK:
742     case SCROLL:
743     case WAND:
744     case ROD:
745     if (QUERY_FLAG (op, FLAG_IDENTIFIED) || QUERY_FLAG (op, FLAG_BEEN_APPLIED))
746     {
747     if (!op->title)
748 root 1.39 buf << " of " << (op->inv ? &op->inv->name : "bug, please report");
749    
750 root 1.20 if (op->type != SPELLBOOK)
751 root 1.39 buf.printf (" (lvl %d)", op->level);
752 root 1.20 }
753     break;
754 elmex 1.1
755    
756 root 1.20 case SKILL:
757     case AMULET:
758     case RING:
759     if (!op->title)
760     {
761     /* If ring has a title, full description isn't so useful */
762 root 1.25 const char *s = ring_desc (op);
763 root 1.4
764 root 1.39 if (s && *s)
765     buf << ' ' << s;
766 root 1.20 }
767     break;
768 root 1.29
769 root 1.20 default:
770     if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED)))
771 root 1.39 buf.printf (" %+d", op->magic);
772 elmex 1.1 }
773 root 1.20
774 root 1.4 return buf;
775 elmex 1.1 }
776    
777     /* Break this off from describe_item - that function was way
778     * too long, making it difficult to read. This function deals
779     * with describing the monsters & players abilities. It should only
780     * be called with monster & player objects. Returns a description
781     * in a static buffer.
782     */
783 root 1.39 static const char *
784 root 1.4 describe_monster (const object *op)
785     {
786 root 1.39 static dynbuf_text buf; buf.clear ();
787 root 1.4
788     /* Note that the resolution this provides for players really isn't
789     * very good. Any player with a speed greater than .67 will
790     * fall into the 'lightning fast movement' category.
791     */
792 elmex 1.16 if (op->has_active_speed ())
793 root 1.65 switch ((int)((fabs (op->speed)) * 15.))
794 root 1.39 {
795     case 0:
796 root 1.51 buf << "(very slow movement)";
797 root 1.39 break;
798     case 1:
799     buf << "(slow movement)";
800     break;
801     case 2:
802     buf << "(normal movement)";
803     break;
804     case 3:
805     case 4:
806     buf << "(fast movement)";
807     break;
808     case 5:
809     case 6:
810     buf << "(very fast movement)";
811     break;
812     case 7:
813     case 8:
814     case 9:
815     case 10:
816     buf << "(extremely fast movement)";
817     break;
818     default:
819     buf << "(lightning fast movement)";
820     break;
821     }
822    
823     if (QUERY_FLAG (op, FLAG_UNDEAD)) buf << "(undead)";
824     if (QUERY_FLAG (op, FLAG_SEE_INVISIBLE)) buf << "(see invisible)";
825     if (QUERY_FLAG (op, FLAG_USE_WEAPON)) buf << "(wield weapon)";
826     if (QUERY_FLAG (op, FLAG_USE_BOW)) buf << "(archer)";
827     if (QUERY_FLAG (op, FLAG_USE_ARMOUR)) buf << "(wear armour)";
828     if (QUERY_FLAG (op, FLAG_USE_RING)) buf << "(wear ring)";
829     if (QUERY_FLAG (op, FLAG_USE_SCROLL)) buf << "(read scroll)";
830     if (QUERY_FLAG (op, FLAG_USE_RANGE)) buf << "(fires wand/rod/horn)";
831     if (QUERY_FLAG (op, FLAG_CAN_USE_SKILL)) buf << "(skill user)";
832     if (QUERY_FLAG (op, FLAG_CAST_SPELL)) buf << "(spellcaster)";
833     if (QUERY_FLAG (op, FLAG_FRIENDLY)) buf << "(friendly)";
834     if (QUERY_FLAG (op, FLAG_UNAGGRESSIVE)) buf << "(unaggressive)";
835     if (QUERY_FLAG (op, FLAG_HITBACK)) buf << "(hitback)";
836     if (QUERY_FLAG (op, FLAG_STEALTH)) buf << "(stealthy)";
837    
838     if (op->randomitems)
839 root 1.4 {
840 root 1.39 bool first = 1;
841 root 1.4
842 root 1.39 for (treasure *t = op->randomitems->items; t; t = t->next)
843 root 1.37 if (t->item && t->item->type == SPELL)
844 root 1.4 {
845     if (first)
846 root 1.39 buf << "(Spell abilities:)";
847    
848     first = 0;
849    
850     buf << '(' << t->item->object::name << ')';
851 root 1.4 }
852     }
853 root 1.39
854 root 1.4 if (op->type == PLAYER)
855     {
856     if (op->contr->digestion)
857 root 1.39 buf.printf ("(sustenance%+d)", op->contr->digestion);
858    
859 root 1.4 if (op->contr->gen_grace)
860 root 1.39 buf.printf ("(grace%+d)", op->contr->gen_grace);
861    
862 root 1.4 if (op->contr->gen_sp)
863 root 1.39 buf.printf ("(magic%+d)", op->contr->gen_sp);
864    
865 root 1.4 if (op->contr->gen_hp)
866 root 1.39 buf.printf ("(regeneration%+d)", op->contr->gen_hp);
867    
868 root 1.4 if (op->stats.luck)
869 root 1.39 buf.printf ("(luck%+d)", op->stats.luck);
870 elmex 1.1 }
871 root 1.4
872     /* describe attacktypes */
873     if (is_dragon_pl (op))
874     {
875     /* for dragon players display the attacktypes from clawing skill
876     * Break apart the for loop - move the comparison checking down -
877     * this makes it more readable.
878     */
879     object *tmp;
880    
881 root 1.39 for (tmp = op->inv; tmp; tmp = tmp->below)
882     if (tmp->type == SKILL && tmp->name == shstr_clawing)
883 root 1.4 break;
884    
885 root 1.39 if (tmp && tmp->attacktype)
886     buf.add_abilities ("Claws", tmp->attacktype);
887 root 1.4 else
888 root 1.39 buf.add_abilities ("Attacks", op->attacktype);
889 elmex 1.1 }
890 root 1.4 else
891 root 1.39 buf.add_abilities ("Attacks", op->attacktype);
892 root 1.21
893 root 1.39 buf.add_paths ("Attuned" , op->path_attuned);
894     buf.add_paths ("Repelled", op->path_repelled);
895     buf.add_paths ("Denied" , op->path_denied);
896 root 1.22
897 root 1.39 for (int i = 0; i < NROFATTACKS; i++)
898 root 1.22 if (op->resist[i])
899 root 1.39 buf.printf ("(%s %+d)", resist_plus[i], op->resist[i]);
900 root 1.22
901 root 1.39 return buf;
902 elmex 1.1 }
903    
904     /*
905     * Returns a pointer to a static buffer which contains a
906     * description of the given object.
907     * If it is a monster, lots of information about its abilities
908     * will be returned.
909     * If it is an item, lots of information about which abilities
910     * will be gained about its user will be returned.
911     * If it is a player, it writes out the current abilities
912     * of the player, which is usually gained by the items applied.
913     * It would be really handy to actually pass another object
914     * pointer on who is examining this object. Then, you could reveal
915     * certain information depending on what the examiner knows, eg,
916     * wouldn't need to use the SEE_INVISIBLE flag to know it is
917     * a dragon player examining food. Could have things like
918     * a dwarven axe, in which the full abilities are only known to
919     * dwarves, etc.
920     *
921     * Add 'owner' who is the person examining this object.
922     * owner can be null if no one is being associated with this
923     * item (eg, debug dump or the like)
924     */
925 root 1.25 const char *
926 root 1.4 describe_item (const object *op, object *owner)
927     {
928 root 1.39 if (QUERY_FLAG (op, FLAG_MONSTER) || op->type == PLAYER)
929     return describe_monster (op);
930    
931     static dynbuf_text buf; buf.clear ();
932 root 1.4 int identified, i;
933    
934     /* figure this out once, instead of making multiple calls to need_identify.
935     * also makes the code easier to read.
936     */
937 root 1.39 identified = !need_identify (op) || QUERY_FLAG (op, FLAG_IDENTIFIED);
938     if (!identified)
939     buf << "(unidentified)";
940    
941 root 1.4 switch (op->type)
942     {
943 root 1.39 case BOW:
944     case ARROW:
945     case WAND:
946     case ROD:
947     case HORN:
948     case WEAPON:
949     case ARMOUR:
950     case HELMET:
951     case SHIELD:
952     case BOOTS:
953     case GLOVES:
954     case GIRDLE:
955     case BRACERS:
956     case CLOAK:
957     case SKILL_TOOL:
958     break; /* We have more information to do below this switch */
959    
960     case POWER_CRYSTAL:
961     if (op->stats.maxsp > 1000)
962     { /*higher capacity crystals */
963     i = (op->stats.maxsp % 1000) / 100;
964    
965     if (i)
966     buf.printf ("(capacity %d.%dk). It is ", op->stats.maxsp / 1000, i);
967     else
968     buf.printf ("(capacity %dk). It is ", op->stats.maxsp / 1000);
969     }
970     else
971     buf.printf ("(capacity %d). It is ", op->stats.maxsp);
972    
973     i = (op->stats.sp * 10) / op->stats.maxsp;
974     if (op->stats.sp == 0)
975     buf << "empty.";
976     else if (i == 0)
977     buf << "almost empty.";
978     else if (i < 3)
979     buf << "partially filled.";
980     else if (i < 6)
981     buf << "half full.";
982     else if (i < 9)
983     buf << "well charged.";
984     else if (op->stats.sp == op->stats.maxsp)
985     buf << "fully charged.";
986     else
987     buf << "almost full.";
988     break;
989    
990 elmex 1.54 case LAMP:
991     {
992     int percent = ((double) 100 / op->arch->stats.food) * op->stats.food;
993     buf << "(fuel: ";
994     if (percent == 0)
995     buf << "empty";
996     else if (percent < 10)
997     buf << "very low";
998     else if (percent < 25)
999     buf << "low";
1000     else if (percent < 50)
1001     buf << "half empty";
1002     else if (percent < 75)
1003     buf << "half full";
1004     else if (percent < 95)
1005     buf << "well filled";
1006     else if (percent <= 100)
1007     buf << "full";
1008     buf << ")";
1009     }
1010     break;
1011    
1012 root 1.39 case FOOD:
1013     case FLESH:
1014     case DRINK:
1015     if (identified || QUERY_FLAG (op, FLAG_BEEN_APPLIED))
1016     {
1017     buf.printf ("(food+%d)", op->stats.food);
1018    
1019     if (op->type == FLESH && op->last_eat > 0 && atnr_is_dragon_enabled (op->last_eat))
1020     buf.printf ("(%s metabolism)", change_resist_msg[op->last_eat]);
1021    
1022     if (!QUERY_FLAG (op, FLAG_CURSED))
1023     {
1024     if (op->stats.hp) buf << "(heals)";
1025     if (op->stats.sp) buf << "(spellpoint regen)";
1026     }
1027     else
1028     {
1029     if (op->stats.hp) buf << "(damages)";
1030     if (op->stats.sp) buf << "(spellpoint depletion)";
1031     }
1032     }
1033     break;
1034    
1035     case SKILL:
1036     case RING:
1037     case AMULET:
1038     if (op->item_power)
1039     buf.printf ("(item_power %+d)", op->item_power);
1040 root 1.2
1041 root 1.39 if (op->title)
1042     buf << ring_desc (op);
1043 root 1.2
1044 root 1.39 return buf;
1045 elmex 1.1
1046 root 1.39 default:
1047     return buf;
1048 elmex 1.1 }
1049    
1050 root 1.4 /* Down here, we more further describe equipment type items.
1051     * only describe them if they have been identified or the like.
1052     */
1053     if (identified || QUERY_FLAG (op, FLAG_BEEN_APPLIED))
1054     {
1055     int attr, val;
1056    
1057     for (attr = 0; attr < NUM_STATS; attr++)
1058 root 1.39 if ((val = op->stats.stat (attr)))
1059     buf.printf ("(%s%+d)", short_stat_name[attr], val);
1060 root 1.2
1061 root 1.4 if (op->stats.exp)
1062 root 1.39 buf.printf ("(speed %+lld)", (long long) op->stats.exp);
1063    
1064     switch (op->type)
1065 root 1.4 {
1066 root 1.39 case BOW:
1067     case ARROW:
1068     case GIRDLE:
1069     case HELMET:
1070     case SHIELD:
1071     case BOOTS:
1072     case GLOVES:
1073     case WEAPON:
1074     case SKILL:
1075     case RING:
1076     case AMULET:
1077     case ARMOUR:
1078     case BRACERS:
1079     case FORCE:
1080     case CLOAK:
1081     if (op->stats.wc) buf.printf ("(wc%+d)", op->stats.wc);
1082     if (op->stats.dam) buf.printf ("(dam%+d)", op->stats.dam);
1083     if (op->stats.ac) buf.printf ("(ac%+d)", op->stats.ac);
1084 root 1.2
1085 root 1.39 if ((op->type == WEAPON || op->type == BOW) && op->level > 0)
1086     buf.printf ("(improved %d/%d)", op->last_eat, op->level);
1087 root 1.2
1088 root 1.39 break;
1089 root 1.2
1090 root 1.39 default:
1091     break;
1092 root 1.2 }
1093 root 1.39
1094     if (QUERY_FLAG (op, FLAG_XRAYS)) buf << "(xray-vision)";
1095     if (QUERY_FLAG (op, FLAG_SEE_IN_DARK)) buf << "(infravision)";
1096 root 1.4
1097     /* levitate was what is was before, so we'll keep it */
1098 root 1.39 if (op->move_type & MOVE_FLY_LOW) buf << "(levitate)";
1099     if (op->move_type & MOVE_FLY_HIGH) buf << "(fly)";
1100     if (op->move_type & MOVE_SWIM) buf << "(swim)";
1101 root 1.4
1102     /* walking is presumed as 'normal', so doesn't need mentioning */
1103    
1104     if (op->item_power)
1105 root 1.39 buf.printf ("(item_power %+d)", op->item_power);
1106 root 1.4 } /* End if identified or applied */
1107    
1108     /* This blocks only deals with fully identified object.
1109     * it is intentional that this is not an 'else' from a above -
1110     * in this way, information is added.
1111     */
1112     if (identified)
1113     {
1114     int more_info = 0;
1115    
1116     switch (op->type)
1117     {
1118 root 1.39 case ROD: /* These use stats.sp for spell selection and stats.food */
1119     case HORN: /* and stats.hp for spell-point regeneration... */
1120     case BOW:
1121     case ARROW:
1122     case WAND:
1123     case FOOD:
1124     case FLESH:
1125     case DRINK:
1126     more_info = 0;
1127     break;
1128    
1129     /* Armor type objects */
1130     case ARMOUR:
1131     case HELMET:
1132     case SHIELD:
1133     case BOOTS:
1134     case GLOVES:
1135     case GIRDLE:
1136     case BRACERS:
1137     case CLOAK:
1138     if (ARMOUR_SPEED (op)) buf.printf ("(Max speed %1.2f)", ARMOUR_SPEED (op) / 10.0);
1139     if (ARMOUR_SPELLS (op)) buf.printf ("(Spell regen penalty %d)", ARMOUR_SPELLS (op));
1140     more_info = 1;
1141     break;
1142 root 1.4
1143 root 1.39 case WEAPON:
1144     /* Calculate it the same way fix_player does so the results
1145     * make sense.
1146     */
1147     i = (WEAPON_SPEED (op) * 2 - op->magic) / 2;
1148     if (i < 0)
1149     i = 0;
1150    
1151     buf.printf ("(weapon speed %d)", i);
1152     more_info = 1;
1153     break;
1154 root 1.4 }
1155 root 1.39
1156 root 1.4 if (more_info)
1157     {
1158 root 1.39 if (op->stats.food) buf.printf ("(sustenance%+d)", op->stats.food);
1159     if (op->stats.grace) buf.printf ("(grace%+d)", op->stats.grace);
1160     if (op->stats.sp) buf.printf ("(magic%+d)", op->stats.sp);
1161     if (op->stats.hp) buf.printf ("(regeneration%+d)", op->stats.hp);
1162 root 1.2 }
1163    
1164 root 1.4 if (op->stats.luck)
1165 root 1.39 buf.printf ("(luck%+d)", op->stats.luck);
1166    
1167     if (QUERY_FLAG (op, FLAG_LIFESAVE)) buf << "(lifesaving)";
1168     if (QUERY_FLAG (op, FLAG_REFL_SPELL)) buf << "(reflect spells)";
1169     if (QUERY_FLAG (op, FLAG_REFL_MISSILE)) buf << "(reflect missiles)";
1170     if (QUERY_FLAG (op, FLAG_STEALTH)) buf << "(stealth)";
1171    
1172     if (op->slaying && op->type != FOOD)
1173     buf.printf ("(slay %s)", &op->slaying);
1174    
1175 root 1.57 if (op->type == SKILL_TOOL && op->skill)
1176     buf.printf ("(%s)", &op->skill);
1177 sf-marcmagus 1.56
1178 root 1.39 buf.add_abilities ("Attacks", op->attacktype);
1179 root 1.4 /* resistance on flesh is only visible for quetzals. If
1180     * non flesh, everyone can see its resistances
1181     */
1182     if (op->type != FLESH || (owner && is_dragon_pl (owner)))
1183 root 1.39 buf << describe_resistance (op, 0);
1184    
1185     buf.add_paths ("Attuned", op->path_attuned);
1186     buf.add_paths ("Repelled", op->path_repelled);
1187     buf.add_paths ("Denied", op->path_denied);
1188 elmex 1.1 }
1189    
1190 root 1.39 return buf;
1191 elmex 1.1 }
1192    
1193 root 1.26 std::string
1194     object::describe_item (object *who)
1195     {
1196     return std::string (::describe_item (this, who));
1197     }
1198    
1199 root 1.40 void
1200     examine (object *op, object *tmp)
1201     {
1202 root 1.45 std::string info = tmp->describe (op);
1203 root 1.55
1204 root 1.45 op->contr->infobox (MSG_CHANNEL ("examine"), info.c_str ());
1205 root 1.40 }
1206    
1207     /*
1208     * inventory prints object's inventory. If inv==NULL then print player's
1209     * inventory.
1210     * [ Only items which are applied are showed. Tero.Haatanen@lut.fi ]
1211     */
1212     const char *
1213     object::query_inventory (object *who, const char *indent)
1214     {
1215     static dynbuf_text buf; buf.clear ();
1216    
1217     for (object *tmp = inv; tmp; tmp = tmp->below)
1218     if (who && QUERY_FLAG (who, FLAG_WIZ))
1219 root 1.53 buf.printf ("%s- %-28.28s (%5d) %-8s\n", indent, tmp->query_name (), tmp->count, tmp->query_weight ());
1220 root 1.40 else if (!tmp->invisible && (type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED)))
1221 root 1.53 buf.printf ("%s- %-36.36s %-8s\n", indent, tmp->query_name (), tmp->query_weight ());
1222 root 1.40
1223     if (buf.size ())
1224 root 1.53 buf.printf ("%s(total weight: %s)\n", indent, query_weight ());
1225 root 1.40 else
1226     buf.printf ("%s(empty)\n", indent);
1227    
1228     return buf;
1229     }
1230    
1231 elmex 1.1 /* Return true if the item is magical. A magical item is one that
1232     * increases/decreases any abilities, provides a resistance,
1233     * has a generic magical bonus, or is an artifact.
1234     * This function is used by detect_magic to determine if an item
1235     * should be marked as magical.
1236     */
1237 root 1.4 int
1238     is_magical (const object *op)
1239     {
1240     int i;
1241 elmex 1.1
1242 root 1.4 /* living creatures are considered non magical */
1243     if (QUERY_FLAG (op, FLAG_ALIVE))
1244     return 0;
1245 elmex 1.1
1246 root 1.4 /* This is a test for it being an artifact, as artifacts have titles */
1247     if (op->title != NULL)
1248     return 1;
1249    
1250     /* Handle rings and amulets specially. If they change any of these
1251     * values, it means they are magical.
1252     */
1253     if ((op->type == AMULET || op->type == RING) &&
1254     (op->stats.ac || op->stats.food || op->stats.exp || op->stats.dam || op->stats.wc || op->stats.sp || op->stats.hp || op->stats.luck))
1255     return 1;
1256    
1257     /* Check for stealty, speed, flying, or just plain magic in the boots */
1258     /* Presume any boots that hvae a move_type are special. */
1259     if (op->type == BOOTS && ((QUERY_FLAG (op, FLAG_STEALTH) || op->move_type || op->stats.exp)))
1260     return 1;
1261    
1262     /* Take care of amulet/shield that reflects spells/missiles */
1263     if ((op->type == AMULET || op->type == SHIELD) && (QUERY_FLAG (op, FLAG_REFL_SPELL) || QUERY_FLAG (op, FLAG_REFL_MISSILE)))
1264     return 1;
1265    
1266     /* Take care of helmet of xrays */
1267     if (op->type == HELMET && QUERY_FLAG (op, FLAG_XRAYS))
1268     return 1;
1269    
1270     /* Potions & rods are always magical. Wands/staves are also magical,
1271     * assuming they still have any charges left.
1272     */
1273     if (op->type == POTION || op->type == ROD || (op->type == WAND && op->stats.food))
1274     return 1;
1275    
1276     /* if something gives a protection, either positive or negative, its magical */
1277     /* This is really a pretty bad hack - as of now, ATNR_PHYSICAL is 0,
1278     * so this always works out fine.
1279     */
1280     for (i = ATNR_PHYSICAL + 1; i < NROFATTACKS; i++)
1281     if (op->resist[i])
1282     return 1;
1283    
1284     /* Physical protection is expected on some item types, so they should
1285     * not be considered magical.
1286     */
1287     if (op->resist[ATNR_PHYSICAL] && op->type != HELMET && op->type != SHIELD &&
1288     op->type != BOOTS && op->type != GLOVES && op->type != ARMOUR)
1289     return 1;
1290    
1291     /* power crystal, spellbooks, and scrolls are always magical. */
1292     if (op->magic || op->type == POWER_CRYSTAL || op->type == SPELLBOOK || op->type == SCROLL || op->type == GIRDLE)
1293     return 1;
1294    
1295     /* Check to see if it increases/decreases any stats */
1296     for (i = 0; i < NUM_STATS; i++)
1297 root 1.33 if (op->stats.stat (i))
1298 root 1.4 return 1;
1299    
1300     /* If it doesn't fall into any of the above categories, must
1301     * be non magical.
1302     */
1303     return 0;
1304 elmex 1.1 }
1305    
1306     /* need_identify returns true if the item should be identified. This
1307     * function really should not exist - by default, any item not identified
1308     * should need it.
1309     */
1310    
1311 root 1.4 int
1312     need_identify (const object *op)
1313     {
1314     switch (op->type)
1315     {
1316 root 1.33 case RING:
1317     case WAND:
1318     case ROD:
1319     case HORN:
1320     case SCROLL:
1321     case SKILL:
1322     case SKILLSCROLL:
1323     case SPELLBOOK:
1324     case FOOD:
1325     case POTION:
1326     case BOW:
1327     case ARROW:
1328     case WEAPON:
1329     case ARMOUR:
1330     case SHIELD:
1331     case HELMET:
1332     case AMULET:
1333     case BOOTS:
1334     case GLOVES:
1335     case BRACERS:
1336     case GIRDLE:
1337     case CONTAINER:
1338     case DRINK:
1339     case FLESH:
1340     case INORGANIC:
1341     case CLOSE_CON:
1342     case CLOAK:
1343     case GEM:
1344     case POWER_CRYSTAL:
1345     case POISON:
1346     case BOOK:
1347     case SKILL_TOOL:
1348     return 1;
1349 elmex 1.1 }
1350 root 1.33
1351 root 1.4 /* Try to track down some stuff that may show up here. Thus, the
1352     * archetype file can be updated, and this function removed.
1353     */
1354 elmex 1.1 #if 0
1355 root 1.4 LOG (llevDebug, "need_identify: %s does not need to be id'd\n", op->name);
1356 elmex 1.1 #endif
1357 root 1.4 return 0;
1358 elmex 1.1 }
1359    
1360     /*
1361     * Supposed to fix face-values as well here, but later.
1362     */
1363 root 1.4 void
1364     identify (object *op)
1365     {
1366     SET_FLAG (op, FLAG_IDENTIFIED);
1367     CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL);
1368     CLEAR_FLAG (op, FLAG_NO_SKILL_IDENT);
1369    
1370     /*
1371     * We want autojoining of equal objects:
1372     */
1373     if (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))
1374     SET_FLAG (op, FLAG_KNOWN_CURSED);
1375    
1376     if (op->type == POTION)
1377     {
1378     if (op->inv && op->randomitems)
1379     op->title = op->inv->name;
1380     else if (op->arch)
1381     {
1382 root 1.48 op->name = op->arch->object::name;
1383 root 1.37 op->name_pl = op->arch->object::name_pl;
1384 root 1.4 }
1385 elmex 1.1 }
1386    
1387 root 1.4 /* If the object is on a map, make sure we update its face */
1388     if (op->map)
1389 root 1.24 update_object (op, UP_OBJ_CHANGE);
1390 root 1.50
1391     if (object *pl = op->visible_to ())
1392 root 1.48 /* A lot of the values can change from an update - might as well send
1393     * it all.
1394     */
1395     esrv_send_item (pl, op);
1396 elmex 1.1 }
1397 root 1.9