ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/item.C
Revision: 1.11
Committed: Wed Dec 20 11:20:50 2006 UTC (17 years, 5 months ago) by elmex
Content type: text/plain
Branch: MAIN
Changes since 1.10: +0 -1 lines
Log Message:
removed QUEST and LIGHTNING types.

File Contents

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