ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/item.C
Revision: 1.60
Committed: Thu Oct 15 20:12:35 2009 UTC (14 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.59: +4 -16 lines
Log Message:
get rid of many buf constants, and users

File Contents

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