ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/item.C
(Generate patch)

Comparing deliantra/server/common/item.C (file contents):
Revision 1.83 by root, Sun Apr 11 00:34:05 2010 UTC vs.
Revision 1.96 by root, Mon Oct 29 23:55:52 2012 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * 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 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 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the Affero GNU General Public License 18 * 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 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24 24
25#include <global.h> 25#include <global.h>
26#include <living.h> 26#include <living.h>
49 * Basically, for the use/nonuse, the code does something like: 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 50 * "This item goes %s\n", with the use/nonuse values filling in the %s
51 */ 51 */
52// see include/object.h 52// see include/object.h
53Body_Locations body_locations[NUM_BODY_LOCATIONS] = { 53Body_Locations body_locations[NUM_BODY_LOCATIONS] = {
54 {KW_body_skill , "You can use it as your skill" , "It is used as a skill"}, 54# define def(name, use, nonuse) { # name, KW_body_ ## name, use, nonuse },
55 {KW_body_combat , "You can wield it as your weapon" , "It is used as a combat weapon"}, 55# include "slotinc.h"
56 {KW_body_range , "You can use it as your range weapon" , "It is used as a range weapon"}, 56# undef def
57 {KW_body_shield , "You can wield it as a shield" , "It is used as a shield"},
58 {KW_body_arm , "You can put it on your arm" , "It goes on a human's arm"},
59 {KW_body_torso , "You can wear it on your body" , "It goes on a human's torso"},
60 {KW_body_head , "You can wear it on your head" , "It goes on a human's head"},
61 {KW_body_neck , "You can wear it around your neck" , "It goes around a human's neck"},
62 {KW_body_finger , "You can wear it on your finger" , "It goes on a human's finger"} ,
63 {KW_body_shoulder, "You can wear it around your shoulders", "It goes around a human's shoulders"},
64 {KW_body_foot , "You can put it on your foot" , "It goes on a human's foot"},
65 {KW_body_hand , "You can put it on your hand" , "It goes on a human's hand"},
66 {KW_body_wrist , "You can wear it around your wrist" , "It goes around a human's wrist"},
67 {KW_body_waist , "You can wear it around your waist" , "It goes around a human's waist"},
68/*{"body_dragon_torso", "your body", "a dragon's body"} */
69}; 57};
70 58
71static char numbers_10[10][20] = { 59static char numbers_10[10][20] = {
72 "zero", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", 60 "zero", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy",
73 "eighty", "ninety" 61 "eighty", "ninety"
158 {INORGANIC, "inorganic", "inorganics", SK_ALCHEMY, 0}, 146 {INORGANIC, "inorganic", "inorganics", SK_ALCHEMY, 0},
159 {SKILL_TOOL, "skill tool", "skill tools", 0, 0}, 147 {SKILL_TOOL, "skill tool", "skill tools", 0, 0},
160 {LIGHTER, "lighter", "lighters", 0, 0}, 148 {LIGHTER, "lighter", "lighters", 0, 0},
161 {BUILDABLE_WALL, "buildable wall", "buildable walls", 0, 0}, 149 {BUILDABLE_WALL, "buildable wall", "buildable walls", 0, 0},
162 {MISC_OBJECT, "bric-a-brac", "bric-a-brac", 0, 0}, 150 {MISC_OBJECT, "bric-a-brac", "bric-a-brac", 0, 0},
151 {TORCH, "torch", "torches", 0, 0},
163 {LAMP, "lamp", "lamps", 0, 0}, 152 {LAMP, "lamp", "lamps", 0, 0},
164 {DUPLICATOR, "duplicator", "duplicators", 0, 0}, 153 {DUPLICATOR, "duplicator", "duplicators", 0, 0},
165 {SPELLBOOK, "spellbook", "spellbooks", SK_LITERACY, 0}, 154 {SPELLBOOK, "spellbook", "spellbooks", SK_LITERACY, 0},
166 {CLOAK, "cloak", "cloaks", SK_SMITHERY, 0}, 155 {CLOAK, "cloak", "cloaks", SK_SMITHERY, 0},
167 {SPINNER, "spinner", "spinners", 0, 0}, 156 {SPINNER, "spinner", "spinners", 0, 0},
202 {BUILDER, "item builder", "item builders", 0, 0}, 191 {BUILDER, "item builder", "item builders", 0, 0},
203 {MATERIAL, "building material", "building materials", 0, 0}, 192 {MATERIAL, "building material", "building materials", 0, 0},
204 {ITEM_TRANSFORMER, "item_transformer", "item_transformers", 0, 0}, 193 {ITEM_TRANSFORMER, "item_transformer", "item_transformers", 0, 0},
205}; 194};
206 195
207static const int item_types_size = sizeof (item_types) / sizeof (*item_types); 196static const int item_types_size = array_length (item_types);
208 197
209/* This curve may be too steep. But the point is that there should 198/* This curve may be too steep. But the point is that there should
210 * be tough choices - there is no real point to this if everyone can 199 * be tough choices - there is no real point to this if everyone can
211 * wear whatever they want with no worries. Perhaps having the steep 200 * wear whatever they want with no worries. Perhaps having the steep
212 * curve is good (maybe even steeper), but allowing players to 201 * curve is good (maybe even steeper), but allowing players to
214 * able to use 2-3 of the most powerful items. 203 * able to use 2-3 of the most powerful items.
215 * note that this table is only really used for program generated items - 204 * note that this table is only really used for program generated items -
216 * custom objects can use whatever they want. 205 * custom objects can use whatever they want.
217 */ 206 */
218static int enc_to_item_power[21] = { 207static int enc_to_item_power[21] = {
208 0,
219 0, 0, 1, 2, 3, 4, /* 5 */ 209 0, 1, 2, 3, 4, // 5
220 5, 7, 9, 11, 13, /* 10 */ 210 5, 7, 9, 11, 13, // 10
221 15, 18, 21, 24, 27, /* 15 */ 211 15, 18, 21, 24, 27, // 15
222 30, 35, 40, 45, 50 /* 20 */ 212 30, 35, 40, 45, 50 // 20
223}; 213};
224 214
225int 215int
226get_power_from_ench (int ench) 216get_power_from_ench (int ench)
227{ 217{
228 return enc_to_item_power [clamp (ench, 0, 20)]; 218 return enc_to_item_power [clamp (ench, 0, 20)];
219}
220
221static const struct need_identify_types : typeset
222{
223 need_identify_types ()
224 {
225 set (RING);
226 set (WAND);
227 set (ROD);
228 set (HORN);
229 set (SCROLL);
230 set (SKILL);
231 set (SKILLSCROLL);
232 set (SPELLBOOK);
233 set (FOOD);
234 set (POTION);
235 set (BOW);
236 set (ARROW);
237 set (WEAPON);
238 set (ARMOUR);
239 set (SHIELD);
240 set (HELMET);
241 set (AMULET);
242 set (BOOTS);
243 set (GLOVES);
244 set (BRACERS);
245 set (GIRDLE);
246 set (CONTAINER);
247 set (DRINK);
248 set (FLESH);
249 set (INORGANIC);
250 set (CLOSE_CON);
251 set (CLOAK);
252 set (GEM);
253 set (POWER_CRYSTAL);
254 set (POISON);
255 set (BOOK);
256 set (SKILL_TOOL);
257 }
258} need_identify_types;
259
260bool
261object::need_identify () const
262{
263 return need_identify_types [type];
229} 264}
230 265
231/* This takes an object 'op' and figures out what its item_power 266/* This takes an object 'op' and figures out what its item_power
232 * rating should be. This should only really be used by the treasure 267 * rating should be. This should only really be used by the treasure
233 * generation code, and when loading legacy objects. It returns 268 * generation code, and when loading legacy objects. It returns
307 if (op->flag [FLAG_MAKE_INVIS ]) enc += 1; 342 if (op->flag [FLAG_MAKE_INVIS ]) enc += 1;
308 343
309 return get_power_from_ench (enc); 344 return get_power_from_ench (enc);
310} 345}
311 346
347static const struct get_typedata
348{
349 const typedata *data [NUM_TYPES];
350
351 get_typedata ()
352 {
353 for (int i = 0; i < item_types_size; i++)
354 data [item_types[i].number] = &item_types [i];
355 }
356
357 const typedata *operator ()(int itemtype) const
358 {
359 return data [itemtype];
360 }
361} get_typedata_;
362
312/* returns the typedata that has a number equal to itemtype, if there 363/* returns the typedata that has a number equal to itemtype, if there
313 * isn't one, returns NULL */ 364 * isn't one, returns NULL */
314const typedata * 365const typedata *
315get_typedata (int itemtype) 366get_typedata (int itemtype)
316{ 367{
317 for (int i = 0; i < item_types_size; i++) 368 return get_typedata_ (itemtype);
318 if (item_types[i].number == itemtype)
319 return &item_types[i];
320
321 return NULL;
322} 369}
323 370
324/* returns the typedata that has a name equal to itemtype, if there 371/* returns the typedata that has a name equal to itemtype, if there
325 * isn't one, return the plural name that matches, if there still isn't 372 * isn't one, return the plural name that matches, if there still isn't
326 * one return NULL */ 373 * one return NULL */
429 */ 476 */
430static const char * 477static const char *
431ring_desc (const object *op) 478ring_desc (const object *op)
432{ 479{
433 static dynbuf_text buf; buf.clear (); 480 static dynbuf_text buf; buf.clear ();
434 int attr, val, len; 481 int attr, val;
435 482
436 if (op->flag [FLAG_IDENTIFIED]) 483 if (op->flag [FLAG_IDENTIFIED])
437 { 484 {
438 for (attr = 0; attr < NUM_STATS; attr++) 485 for (attr = 0; attr < NUM_STATS; attr++)
439 if ((val = op->stats.stat (attr))) 486 if ((val = op->stats.stat (attr)))
440 buf.printf ("(%s%+d)", short_stat_name[attr], val); 487 buf.printf ("(%s%+d)", short_stat_name[attr], val);
441 488
442 if (op->stats.exp) buf.printf ("(speed %+lld)", (long long)op->stats.exp); 489 if (op->stats.exp) buf.printf ("(speed %+d)", (int)op->stats.exp);
443 if (op->stats.wc) buf.printf ("(wc%+d)", op->stats.wc); 490 if (op->stats.wc) buf.printf ("(wc%+d)", op->stats.wc);
444 if (op->stats.dam) buf.printf ("(dam%+d)", op->stats.dam); 491 if (op->stats.dam) buf.printf ("(dam%+d)", op->stats.dam);
445 if (op->stats.ac) buf.printf ("(ac%+d)", op->stats.ac); 492 if (op->stats.ac) buf.printf ("(ac%+d)", op->stats.ac);
446 493
447 buf << describe_resistance (op, 0); 494 buf << describe_resistance (op, 0);
547 buf << " " << s; 594 buf << " " << s;
548 } 595 }
549 break; 596 break;
550 597
551 default: 598 default:
552 if (op->magic && ((op->flag [FLAG_BEEN_APPLIED] && need_identify (op)) || op->flag [FLAG_IDENTIFIED])) 599 if (op->magic
600 && ((op->flag [FLAG_BEEN_APPLIED] && op->need_identify ())
601 || op->flag [FLAG_IDENTIFIED]))
553 buf.printf (" %+d", op->magic); 602 buf.printf (" %+d", op->magic);
554 } 603 }
555 604
556 return buf; 605 return buf;
557} 606}
571 * It is also used by examine/ex and similar functions. 620 * It is also used by examine/ex and similar functions.
572 */ 621 */
573const char * 622const char *
574query_name (const object *op) 623query_name (const object *op)
575{ 624{
576 int len = 0;
577 static dynbuf_text bufs[5]; 625 static dynbuf_text bufs[5];
578 static int use_buf = 0; 626 static int use_buf = 0;
579 627
580 use_buf++; 628 use_buf++;
581 use_buf %= 5; 629 use_buf %= 5;
626 674
627 if (op->flag [FLAG_APPLIED]) 675 if (op->flag [FLAG_APPLIED])
628 { 676 {
629 switch (op->type) 677 switch (op->type)
630 { 678 {
679 case RANGED:
631 case BOW: 680 case BOW:
632 case WAND: 681 case WAND:
633 case ROD: 682 case ROD:
634 case HORN: 683 case HORN:
635 buf << " (applied)";
636 break;
637 case WEAPON: 684 case WEAPON:
638 buf << " (applied)"; 685 buf << " (applied)";
639 break; 686 break;
640 case ARMOUR: 687 case ARMOUR:
641 case HELMET: 688 case HELMET:
756 else if (!EXIT_PATH (op)) 803 else if (!EXIT_PATH (op))
757 buf << " (closed)"; 804 buf << " (closed)";
758 break; 805 break;
759 806
760 default: 807 default:
761 if (op->magic && ((op->flag [FLAG_BEEN_APPLIED] && need_identify (op)) || op->flag [FLAG_IDENTIFIED])) 808 if (op->magic
809 && ((op->flag [FLAG_BEEN_APPLIED] && op->need_identify ())
810 || op->flag [FLAG_IDENTIFIED]))
762 buf.printf (" %+d", op->magic); 811 buf.printf (" %+d", op->magic);
763 } 812 }
764 813
765 return buf; 814 return buf;
766} 815}
923 int identified, i; 972 int identified, i;
924 973
925 /* figure this out once, instead of making multiple calls to need_identify. 974 /* figure this out once, instead of making multiple calls to need_identify.
926 * also makes the code easier to read. 975 * also makes the code easier to read.
927 */ 976 */
928 identified = !need_identify (op) || op->flag [FLAG_IDENTIFIED]; 977 identified = !op->need_identify () || op->flag [FLAG_IDENTIFIED];
929 if (!identified) 978 if (!identified)
930 buf << "(unidentified)"; 979 buf << "(unidentified)";
931 980
932 switch (op->type) 981 switch (op->type)
933 { 982 {
983 case RANGED:
934 case BOW: 984 case BOW:
935 case ARROW: 985 case ARROW:
936 case WAND: 986 case WAND:
937 case ROD: 987 case ROD:
938 case HORN: 988 case HORN:
1043 /* Down here, we more further describe equipment type items. 1093 /* Down here, we more further describe equipment type items.
1044 * only describe them if they have been identified or the like. 1094 * only describe them if they have been identified or the like.
1045 */ 1095 */
1046 if (identified || op->flag [FLAG_BEEN_APPLIED]) 1096 if (identified || op->flag [FLAG_BEEN_APPLIED])
1047 { 1097 {
1048 int attr, val;
1049
1050 for (attr = 0; attr < NUM_STATS; attr++) 1098 for (int attr = 0; attr < NUM_STATS; attr++)
1051 if ((val = op->stats.stat (attr))) 1099 if (int val = op->stats.stat (attr))
1052 buf.printf ("(%s%+d)", short_stat_name[attr], val); 1100 buf.printf ("(%s%+d)", short_stat_name[attr], val);
1053 1101
1054 if (op->stats.exp) 1102 if (op->stats.exp)
1055 buf.printf ("(speed %+lld)", (long long) op->stats.exp); 1103 buf.printf ("(speed %+lld)", (long long) op->stats.exp);
1056 1104
1057 switch (op->type) 1105 switch (op->type)
1058 { 1106 {
1107 case RANGED:
1059 case BOW: 1108 case BOW:
1060 case ARROW: 1109 case ARROW:
1061 case GIRDLE: 1110 case GIRDLE:
1062 case HELMET: 1111 case HELMET:
1063 case SHIELD: 1112 case SHIELD:
1106 { 1155 {
1107 int more_info = 0; 1156 int more_info = 0;
1108 1157
1109 switch (op->type) 1158 switch (op->type)
1110 { 1159 {
1160 case RANGED:
1111 case ROD: /* These use stats.sp for spell selection and stats.food */ 1161 case ROD: /* These use stats.sp for spell selection and stats.food */
1112 case HORN: /* and stats.hp for spell-point regeneration... */ 1162 case HORN: /* and stats.hp for spell-point regeneration... */
1113 case BOW: 1163 case BOW:
1114 case ARROW: 1164 case ARROW:
1115 case WAND: 1165 case WAND:
1291 */ 1341 */
1292 if (msg) 1342 if (msg)
1293 { 1343 {
1294 if (type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ()) 1344 if (type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ())
1295 { 1345 {
1296 buf << '\r'; 1346 if (!need_identify ())
1297 1347 buf << '\r' << msg << '\n';
1298 /* This is just a hack so when identifying the items, we print 1348 else if (flag [FLAG_IDENTIFIED])
1299 * out the extra message
1300 */
1301 if (need_identify (this) && flag [FLAG_IDENTIFIED])
1302 buf << "The object has a story:\r"; 1349 buf << '\r' << "The object has a story:\r" << msg;
1303
1304 buf << msg << '\n';
1305 } 1350 }
1306 } 1351 }
1307 else if (inv && inv->type == SPELL && flag [FLAG_IDENTIFIED] 1352 else if (inv
1353 && inv->msg
1354 && inv->type == SPELL
1355 && flag [FLAG_IDENTIFIED]
1308 && (type == SPELLBOOK || type == ROD || type == WAND 1356 && (type == SPELLBOOK || type == ROD || type == WAND
1309 || type == ROD || type == POTION || type == SCROLL)) 1357 || type == POTION || type == SCROLL))
1310 // for spellbooks and other stuff that contains spells, print the spell message, 1358 // for spellbooks and other stuff that contains spells, print the spell message,
1311 // unless the object has a custom message handled above. 1359 // unless the object has a custom message handled above.
1312 buf << '\r' << inv->msg << '\n'; 1360 buf << '\r' << inv->msg << '\n';
1313 1361
1314 // try to display the duration for some potions and scrolls 1362 // try to display the duration for some potions and scrolls
1466 * be non magical. 1514 * be non magical.
1467 */ 1515 */
1468 return 0; 1516 return 0;
1469} 1517}
1470 1518
1471/* need_identify returns true if the item should be identified. This
1472 * function really should not exist - by default, any item not identified
1473 * should need it.
1474 */
1475
1476int
1477need_identify (const object *op)
1478{
1479 switch (op->type)
1480 {
1481 case RING:
1482 case WAND:
1483 case ROD:
1484 case HORN:
1485 case SCROLL:
1486 case SKILL:
1487 case SKILLSCROLL:
1488 case SPELLBOOK:
1489 case FOOD:
1490 case POTION:
1491 case BOW:
1492 case ARROW:
1493 case WEAPON:
1494 case ARMOUR:
1495 case SHIELD:
1496 case HELMET:
1497 case AMULET:
1498 case BOOTS:
1499 case GLOVES:
1500 case BRACERS:
1501 case GIRDLE:
1502 case CONTAINER:
1503 case DRINK:
1504 case FLESH:
1505 case INORGANIC:
1506 case CLOSE_CON:
1507 case CLOAK:
1508 case GEM:
1509 case POWER_CRYSTAL:
1510 case POISON:
1511 case BOOK:
1512 case SKILL_TOOL:
1513 return 1;
1514 }
1515
1516 /* Try to track down some stuff that may show up here. Thus, the
1517 * archetype file can be updated, and this function removed.
1518 */
1519#if 0
1520 LOG (llevDebug, "need_identify: %s does not need to be id'd\n", op->name);
1521#endif
1522 return 0;
1523}
1524
1525/* 1519/*
1526 * Supposed to fix face-values as well here, but later. 1520 * Supposed to fix face-values as well here, but later.
1527 */ 1521 */
1528void 1522void
1529identify (object *op) 1523identify (object *op)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines