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.87 by root, Fri Apr 30 21:13:41 2010 UTC

202 {BUILDER, "item builder", "item builders", 0, 0}, 202 {BUILDER, "item builder", "item builders", 0, 0},
203 {MATERIAL, "building material", "building materials", 0, 0}, 203 {MATERIAL, "building material", "building materials", 0, 0},
204 {ITEM_TRANSFORMER, "item_transformer", "item_transformers", 0, 0}, 204 {ITEM_TRANSFORMER, "item_transformer", "item_transformers", 0, 0},
205}; 205};
206 206
207static const int item_types_size = sizeof (item_types) / sizeof (*item_types); 207static const int item_types_size = array_length (item_types);
208 208
209/* This curve may be too steep. But the point is that there should 209/* 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 210 * 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 211 * wear whatever they want with no worries. Perhaps having the steep
212 * curve is good (maybe even steeper), but allowing players to 212 * curve is good (maybe even steeper), but allowing players to
214 * able to use 2-3 of the most powerful items. 214 * able to use 2-3 of the most powerful items.
215 * note that this table is only really used for program generated items - 215 * note that this table is only really used for program generated items -
216 * custom objects can use whatever they want. 216 * custom objects can use whatever they want.
217 */ 217 */
218static int enc_to_item_power[21] = { 218static int enc_to_item_power[21] = {
219 0,
219 0, 0, 1, 2, 3, 4, /* 5 */ 220 0, 1, 2, 3, 4, // 5
220 5, 7, 9, 11, 13, /* 10 */ 221 5, 7, 9, 11, 13, // 10
221 15, 18, 21, 24, 27, /* 15 */ 222 15, 18, 21, 24, 27, // 15
222 30, 35, 40, 45, 50 /* 20 */ 223 30, 35, 40, 45, 50 // 20
223}; 224};
224 225
225int 226int
226get_power_from_ench (int ench) 227get_power_from_ench (int ench)
227{ 228{
228 return enc_to_item_power [clamp (ench, 0, 20)]; 229 return enc_to_item_power [clamp (ench, 0, 20)];
230}
231
232static const struct need_identify_types : typeset
233{
234 need_identify_types ()
235 {
236 set (RING);
237 set (WAND);
238 set (ROD);
239 set (HORN);
240 set (SCROLL);
241 set (SKILL);
242 set (SKILLSCROLL);
243 set (SPELLBOOK);
244 set (FOOD);
245 set (POTION);
246 set (BOW);
247 set (ARROW);
248 set (WEAPON);
249 set (ARMOUR);
250 set (SHIELD);
251 set (HELMET);
252 set (AMULET);
253 set (BOOTS);
254 set (GLOVES);
255 set (BRACERS);
256 set (GIRDLE);
257 set (CONTAINER);
258 set (DRINK);
259 set (FLESH);
260 set (INORGANIC);
261 set (CLOSE_CON);
262 set (CLOAK);
263 set (GEM);
264 set (POWER_CRYSTAL);
265 set (POISON);
266 set (BOOK);
267 set (SKILL_TOOL);
268 }
269} need_identify_types;
270
271bool
272object::need_identify () const
273{
274 return need_identify_types [type];
229} 275}
230 276
231/* This takes an object 'op' and figures out what its item_power 277/* 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 278 * rating should be. This should only really be used by the treasure
233 * generation code, and when loading legacy objects. It returns 279 * generation code, and when loading legacy objects. It returns
307 if (op->flag [FLAG_MAKE_INVIS ]) enc += 1; 353 if (op->flag [FLAG_MAKE_INVIS ]) enc += 1;
308 354
309 return get_power_from_ench (enc); 355 return get_power_from_ench (enc);
310} 356}
311 357
358static const struct get_typedata
359{
360 const typedata *data [NUM_TYPES];
361
362 get_typedata ()
363 {
364 for (int i = 0; i < item_types_size; i++)
365 data [item_types[i].number] = &item_types [i];
366 }
367
368 const typedata *operator ()(int itemtype) const
369 {
370 return data [itemtype];
371 }
372} get_typedata_;
373
312/* returns the typedata that has a number equal to itemtype, if there 374/* returns the typedata that has a number equal to itemtype, if there
313 * isn't one, returns NULL */ 375 * isn't one, returns NULL */
314const typedata * 376const typedata *
315get_typedata (int itemtype) 377get_typedata (int itemtype)
316{ 378{
317 for (int i = 0; i < item_types_size; i++) 379 return get_typedata_ (itemtype);
318 if (item_types[i].number == itemtype)
319 return &item_types[i];
320
321 return NULL;
322} 380}
323 381
324/* returns the typedata that has a name equal to itemtype, if there 382/* 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 383 * isn't one, return the plural name that matches, if there still isn't
326 * one return NULL */ 384 * one return NULL */
547 buf << " " << s; 605 buf << " " << s;
548 } 606 }
549 break; 607 break;
550 608
551 default: 609 default:
552 if (op->magic && ((op->flag [FLAG_BEEN_APPLIED] && need_identify (op)) || op->flag [FLAG_IDENTIFIED])) 610 if (op->magic
611 && ((op->flag [FLAG_BEEN_APPLIED] && op->need_identify ())
612 || op->flag [FLAG_IDENTIFIED]))
553 buf.printf (" %+d", op->magic); 613 buf.printf (" %+d", op->magic);
554 } 614 }
555 615
556 return buf; 616 return buf;
557} 617}
756 else if (!EXIT_PATH (op)) 816 else if (!EXIT_PATH (op))
757 buf << " (closed)"; 817 buf << " (closed)";
758 break; 818 break;
759 819
760 default: 820 default:
761 if (op->magic && ((op->flag [FLAG_BEEN_APPLIED] && need_identify (op)) || op->flag [FLAG_IDENTIFIED])) 821 if (op->magic
822 && ((op->flag [FLAG_BEEN_APPLIED] && op->need_identify ())
823 || op->flag [FLAG_IDENTIFIED]))
762 buf.printf (" %+d", op->magic); 824 buf.printf (" %+d", op->magic);
763 } 825 }
764 826
765 return buf; 827 return buf;
766} 828}
923 int identified, i; 985 int identified, i;
924 986
925 /* figure this out once, instead of making multiple calls to need_identify. 987 /* figure this out once, instead of making multiple calls to need_identify.
926 * also makes the code easier to read. 988 * also makes the code easier to read.
927 */ 989 */
928 identified = !need_identify (op) || op->flag [FLAG_IDENTIFIED]; 990 identified = !op->need_identify () || op->flag [FLAG_IDENTIFIED];
929 if (!identified) 991 if (!identified)
930 buf << "(unidentified)"; 992 buf << "(unidentified)";
931 993
932 switch (op->type) 994 switch (op->type)
933 { 995 {
1291 */ 1353 */
1292 if (msg) 1354 if (msg)
1293 { 1355 {
1294 if (type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ()) 1356 if (type != EXIT && type != BOOK && type != CORPSE && !move_on && !has_dialogue ())
1295 { 1357 {
1296 buf << '\r'; 1358 if (!need_identify ())
1297 1359 buf << '\r' << msg << '\n';
1298 /* This is just a hack so when identifying the items, we print 1360 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"; 1361 buf << '\r' << "The object has a story:\r" << msg;
1303
1304 buf << msg << '\n';
1305 } 1362 }
1306 } 1363 }
1307 else if (inv && inv->type == SPELL && flag [FLAG_IDENTIFIED] 1364 else if (inv
1365 && inv->msg
1366 && inv->type == SPELL
1367 && flag [FLAG_IDENTIFIED]
1308 && (type == SPELLBOOK || type == ROD || type == WAND 1368 && (type == SPELLBOOK || type == ROD || type == WAND
1309 || type == ROD || type == POTION || type == SCROLL)) 1369 || type == ROD || type == POTION || type == SCROLL))
1310 // for spellbooks and other stuff that contains spells, print the spell message, 1370 // for spellbooks and other stuff that contains spells, print the spell message,
1311 // unless the object has a custom message handled above. 1371 // unless the object has a custom message handled above.
1312 buf << '\r' << inv->msg << '\n'; 1372 buf << '\r' << inv->msg << '\n';
1466 * be non magical. 1526 * be non magical.
1467 */ 1527 */
1468 return 0; 1528 return 0;
1469} 1529}
1470 1530
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/* 1531/*
1526 * Supposed to fix face-values as well here, but later. 1532 * Supposed to fix face-values as well here, but later.
1527 */ 1533 */
1528void 1534void
1529identify (object *op) 1535identify (object *op)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines