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.23 by root, Fri Feb 16 19:43:40 2007 UTC vs.
Revision 1.28 by root, Wed May 2 05:59:06 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 * 7 *
250}; 250};
251 251
252int 252int
253get_power_from_ench (int ench) 253get_power_from_ench (int ench)
254{ 254{
255 if (ench < 0) 255 if (ench < 0) ench = 0;
256 ench = 0; 256 if (ench > 20) ench = 20;
257 if (ench > 20) 257
258 ench = 20;
259 return enc_to_item_power[ench]; 258 return enc_to_item_power[ench];
260} 259}
261 260
262/* This takes an object 'op' and figures out what its item_power 261/* This takes an object 'op' and figures out what its item_power
263 * rating should be. This should only really be used by the treasure 262 * rating should be. This should only really be used by the treasure
342 enc += 1; 341 enc += 1;
343 if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) 342 if (QUERY_FLAG (op, FLAG_MAKE_INVIS))
344 enc += 1; 343 enc += 1;
345 344
346 return get_power_from_ench (enc); 345 return get_power_from_ench (enc);
347
348} 346}
349 347
350/* returns the typedata that has a number equal to itemtype, if there 348/* returns the typedata that has a number equal to itemtype, if there
351 * isn't one, returns NULL */ 349 * isn't one, returns NULL */
352
353const typedata * 350const typedata *
354get_typedata (int itemtype) 351get_typedata (int itemtype)
355{ 352{
356 int i; 353 int i;
357 354
362} 359}
363 360
364/* returns the typedata that has a name equal to itemtype, if there 361/* returns the typedata that has a name equal to itemtype, if there
365 * isn't one, return the plural name that matches, if there still isn't 362 * isn't one, return the plural name that matches, if there still isn't
366 * one return NULL */ 363 * one return NULL */
367
368const typedata * 364const typedata *
369get_typedata_by_name (const char *name) 365get_typedata_by_name (const char *name)
370{ 366{
371 int i; 367 int i;
372 368
387 * returns a static array of the description. This can return 383 * returns a static array of the description. This can return
388 * a big buffer. 384 * a big buffer.
389 * if newline is true, we don't put parens around the description 385 * if newline is true, we don't put parens around the description
390 * but do put a newline at the end. Useful when dumping to files 386 * but do put a newline at the end. Useful when dumping to files
391 */ 387 */
392char * 388const char *
393describe_resistance (const object *op, int newline) 389describe_resistance (const object *op, int newline)
394{ 390{
395 static char buf[VERY_BIG_BUF]; 391 static char buf[VERY_BIG_BUF];
396 char buf1[VERY_BIG_BUF]; 392 char buf1[VERY_BIG_BUF];
397 int tmpvar; 393 int tmpvar;
416/* 412/*
417 * query_weight(object) returns a character pointer to a static buffer 413 * query_weight(object) returns a character pointer to a static buffer
418 * containing the text-representation of the weight of the given object. 414 * containing the text-representation of the weight of the given object.
419 * The buffer will be overwritten by the next call to query_weight(). 415 * The buffer will be overwritten by the next call to query_weight().
420 */ 416 */
421 417const char *
422char *
423query_weight (const object *op) 418query_weight (const object *op)
424{ 419{
425 static char buf[10]; 420 static char buf[10];
426 sint32 i = (op->nrof ? op->nrof : 1) * op->weight + op->carrying; 421 sint32 i = (op->nrof ? op->nrof : 1) * op->weight + op->carrying;
427 422
428 if (op->weight < 0) 423 if (op->weight < 0)
429 return " "; 424 return " ";
425
430 if (i % 1000) 426 if (i % 1000)
431 sprintf (buf, "%6.1f", i / 1000.0); 427 sprintf (buf, "%6.1f", i / 1000.0);
432 else 428 else
433 sprintf (buf, "%4d ", i / 1000); 429 sprintf (buf, "%4d ", i / 1000);
430
434 return buf; 431 return buf;
435} 432}
436 433
437/* 434/*
438 * Returns the pointer to a static buffer containing 435 * Returns the pointer to a static buffer containing
439 * the number requested (of the form first, second, third...) 436 * the number requested (of the form first, second, third...)
440 */ 437 */
441 438const char *
442char *
443get_levelnumber (int i) 439get_levelnumber (int i)
444{ 440{
445 static char buf[MAX_BUF]; 441 static char buf[MAX_BUF];
446 442
447 if (i > 99) 443 if (i > 99)
448 { 444 {
449 sprintf (buf, "%d.", i); 445 sprintf (buf, "%d.", i);
450 return buf; 446 return buf;
451 } 447 }
448
452 if (i < 21) 449 if (i < 21)
453 return levelnumbers[i]; 450 return levelnumbers[i];
454 if (!(i % 10)) 451 if (!(i % 10))
455 return levelnumbers_10[i / 10]; 452 return levelnumbers_10[i / 10];
453
456 strcpy (buf, numbers_10[i / 10]); 454 strcpy (buf, numbers_10[i / 10]);
457 strcat (buf, levelnumbers[i % 10]); 455 strcat (buf, levelnumbers[i % 10]);
458 return buf; 456 return buf;
459} 457}
460 458
462 * get_number(integer) returns the text-representation of the given number 460 * get_number(integer) returns the text-representation of the given number
463 * in a static buffer. The buffer might be overwritten at the next 461 * in a static buffer. The buffer might be overwritten at the next
464 * call to get_number(). 462 * call to get_number().
465 * It is currently only used by the query_name() function. 463 * It is currently only used by the query_name() function.
466 */ 464 */
467char * 465const char *
468get_number (int i) 466get_number (int i)
469{ 467{
470 if (i <= 20) 468 if (i <= 20)
471 return numbers[i]; 469 return numbers[i];
472 else 470 else
489 */ 487 */
490 488
491/* Aug 95 modified this slightly so that Skill tools don't have magic bonus 489/* Aug 95 modified this slightly so that Skill tools don't have magic bonus
492 * from stats.sp - b.t. 490 * from stats.sp - b.t.
493 */ 491 */
494char * 492const char *
495ring_desc (const object *op) 493ring_desc (const object *op)
496{ 494{
497 static char buf[VERY_BIG_BUF]; 495 static char buf[VERY_BIG_BUF];
498 int attr, val, len; 496 int attr, val, len;
499 497
507 if ((val = get_attr_value (&(op->stats), attr)) != 0) 505 if ((val = get_attr_value (&(op->stats), attr)) != 0)
508 { 506 {
509 sprintf (buf + strlen (buf), "(%s%+d)", short_stat_name[attr], val); 507 sprintf (buf + strlen (buf), "(%s%+d)", short_stat_name[attr], val);
510 } 508 }
511 } 509 }
510
512 if (op->stats.exp) 511 if (op->stats.exp)
513 sprintf (buf + strlen (buf), "(speed %+lld)", (long long) op->stats.exp); 512 sprintf (buf + strlen (buf), "(speed %+lld)", (long long) op->stats.exp);
514 if (op->stats.wc) 513 if (op->stats.wc)
515 sprintf (buf + strlen (buf), "(wc%+d)", op->stats.wc); 514 sprintf (buf + strlen (buf), "(wc%+d)", op->stats.wc);
516 if (op->stats.dam) 515 if (op->stats.dam)
538 strcat (buf, "(reflect spells)"); 537 strcat (buf, "(reflect spells)");
539 if (QUERY_FLAG (op, FLAG_REFL_MISSILE)) 538 if (QUERY_FLAG (op, FLAG_REFL_MISSILE))
540 strcat (buf, "(reflect missiles)"); 539 strcat (buf, "(reflect missiles)");
541 if (QUERY_FLAG (op, FLAG_STEALTH)) 540 if (QUERY_FLAG (op, FLAG_STEALTH))
542 strcat (buf, "(stealth)"); 541 strcat (buf, "(stealth)");
542
543 /* Shorten some of the names, so they appear better in the windows */ 543 /* Shorten some of the names, so they appear better in the windows */
544 len = strlen (buf); 544 len = strlen (buf);
545 DESCRIBE_PATH_SAFE (buf, op->path_attuned, "Attuned", &len, VERY_BIG_BUF); 545 DESCRIBE_PATH_SAFE (buf, op->path_attuned, "Attuned", &len, VERY_BIG_BUF);
546 DESCRIBE_PATH_SAFE (buf, op->path_repelled, "Repelled", &len, VERY_BIG_BUF); 546 DESCRIBE_PATH_SAFE (buf, op->path_repelled, "Repelled", &len, VERY_BIG_BUF);
547 DESCRIBE_PATH_SAFE (buf, op->path_denied, "Denied", &len, VERY_BIG_BUF); 547 DESCRIBE_PATH_SAFE (buf, op->path_denied, "Denied", &len, VERY_BIG_BUF);
612 case AMULET: 612 case AMULET:
613 case RING: 613 case RING:
614 if (!op->title) 614 if (!op->title)
615 { 615 {
616 /* If ring has a title, full description isn't so useful */ 616 /* If ring has a title, full description isn't so useful */
617 char *s = ring_desc (op); 617 const char *s = ring_desc (op);
618 618
619 if (s[0]) 619 if (s[0])
620 { 620 {
621 safe_strcat (buf, " ", &len, HUGE_BUF); 621 safe_strcat (buf, " ", &len, HUGE_BUF);
622 safe_strcat (buf, s, &len, HUGE_BUF); 622 safe_strcat (buf, s, &len, HUGE_BUF);
642 * overwritten. This may be a bad thing (it may be easier to assume the value 642 * overwritten. This may be a bad thing (it may be easier to assume the value
643 * returned is good forever.) However, it makes printing statements that 643 * returned is good forever.) However, it makes printing statements that
644 * use several names much easier (don't need to store them to temp variables.) 644 * use several names much easier (don't need to store them to temp variables.)
645 * 645 *
646 */ 646 */
647char * 647const char *
648query_name (const object *op) 648query_name (const object *op)
649{ 649{
650 static char buf[5][HUGE_BUF]; // OMFG 650 static char buf[5][HUGE_BUF]; // OMFG
651 static int use_buf = 0; 651 static int use_buf = 0;
652 int len = 0; 652 int len = 0;
712 { 712 {
713 case BOW: 713 case BOW:
714 case WAND: 714 case WAND:
715 case ROD: 715 case ROD:
716 case HORN: 716 case HORN:
717 safe_strcat (buf[use_buf], " (readied)", &len, HUGE_BUF); 717 safe_strcat (buf[use_buf], op->env && op->env->current_weapon == op ? " (readied)" : " (applied)", &len, HUGE_BUF);
718 break; 718 break;
719 case WEAPON: 719 case WEAPON:
720 safe_strcat (buf[use_buf], " (wielded)", &len, HUGE_BUF); 720 safe_strcat (buf[use_buf], op->env && op->env->current_weapon == op ? " (wielded)" : " (applied)", &len, HUGE_BUF);
721 break; 721 break;
722 case ARMOUR: 722 case ARMOUR:
723 case HELMET: 723 case HELMET:
724 case SHIELD: 724 case SHIELD:
725 case RING: 725 case RING:
831 case AMULET: 831 case AMULET:
832 case RING: 832 case RING:
833 if (!op->title) 833 if (!op->title)
834 { 834 {
835 /* If ring has a title, full description isn't so useful */ 835 /* If ring has a title, full description isn't so useful */
836 char *s = ring_desc (op); 836 const char *s = ring_desc (op);
837 837
838 if (s[0]) 838 if (s[0])
839 { 839 {
840 safe_strcat (buf, " ", &len, MAX_BUF); 840 safe_strcat (buf, " ", &len, MAX_BUF);
841 safe_strcat (buf, s, &len, MAX_BUF); 841 safe_strcat (buf, s, &len, MAX_BUF);
1039 * 1039 *
1040 * Add 'owner' who is the person examining this object. 1040 * Add 'owner' who is the person examining this object.
1041 * owner can be null if no one is being associated with this 1041 * owner can be null if no one is being associated with this
1042 * item (eg, debug dump or the like) 1042 * item (eg, debug dump or the like)
1043 */ 1043 */
1044 1044const char *
1045char *
1046describe_item (const object *op, object *owner) 1045describe_item (const object *op, object *owner)
1047{ 1046{
1048 char buf[MAX_BUF]; 1047 char buf[MAX_BUF];
1049 static char retbuf[VERY_BIG_BUF]; 1048 static char retbuf[VERY_BIG_BUF];
1050 int identified, i; 1049 int identified, i;
1360 } 1359 }
1361 1360
1362 return retbuf; 1361 return retbuf;
1363} 1362}
1364 1363
1364std::string
1365object::describe_item (object *who)
1366{
1367 return std::string (::describe_item (this, who));
1368}
1369
1365/* Return true if the item is magical. A magical item is one that 1370/* Return true if the item is magical. A magical item is one that
1366 * increases/decreases any abilities, provides a resistance, 1371 * increases/decreases any abilities, provides a resistance,
1367 * has a generic magical bonus, or is an artifact. 1372 * has a generic magical bonus, or is an artifact.
1368 * This function is used by detect_magic to determine if an item 1373 * This function is used by detect_magic to determine if an item
1369 * should be marked as magical. 1374 * should be marked as magical.
1520 } 1525 }
1521 } 1526 }
1522 1527
1523 /* If the object is on a map, make sure we update its face */ 1528 /* If the object is on a map, make sure we update its face */
1524 if (op->map) 1529 if (op->map)
1525 update_object (op, UP_OBJ_FACE); 1530 update_object (op, UP_OBJ_CHANGE);
1526 else 1531 else
1527 { 1532 {
1528 pl = op->in_player (); 1533 pl = op->in_player ();
1529 if (pl) 1534 if (pl)
1530 /* A lot of the values can change from an update - might as well send 1535 /* A lot of the values can change from an update - might as well send

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines