ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/item.c
Revision: 1.1.1.3 (vendor branch)
Committed: Wed Mar 15 14:04:36 2006 UTC (18 years, 2 months ago) by elmex
Content type: text/plain
Branch: UPSTREAM
CVS Tags: UPSTREAM_2006_03_15, LAST_C_VERSION, difficulty_fix_merge_060810_2300
Branch point for: difficulty_fix
Changes since 1.1.1.2: +1 -2 lines
Log Message:
cvs -z9 -d:ext:elmex@cvs.schmorp.de:/schmorpforge import cf.schmorp.de UPSTREAM UPSTREAM_2006_03_15

File Contents

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