ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/item.c
Revision: 1.2
Committed: Sun Aug 13 17:16:00 2006 UTC (17 years, 9 months ago) by elmex
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -1 lines
State: FILE REMOVED
Log Message:
Made server compile with C++.
Removed cfanim plugin and crossedit.
C++ here we come.

File Contents

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