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.15 by elmex, Wed Dec 20 14:38:50 2006 UTC vs.
Revision 1.26 by root, Mon Apr 23 18:09:57 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
3 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
6 7 *
7 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 21 *
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 23 */
23 24
24#include <global.h> 25#include <global.h>
25#include <funcpoint.h> 26#include <funcpoint.h>
26#include <living.h> 27#include <living.h>
27#include <spells.h> 28#include <spells.h>
386 * returns a static array of the description. This can return 387 * returns a static array of the description. This can return
387 * a big buffer. 388 * a big buffer.
388 * if newline is true, we don't put parens around the description 389 * if newline is true, we don't put parens around the description
389 * but do put a newline at the end. Useful when dumping to files 390 * but do put a newline at the end. Useful when dumping to files
390 */ 391 */
391char * 392const char *
392describe_resistance (const object *op, int newline) 393describe_resistance (const object *op, int newline)
393{ 394{
394 static char buf[VERY_BIG_BUF]; 395 static char buf[VERY_BIG_BUF];
395 char buf1[VERY_BIG_BUF]; 396 char buf1[VERY_BIG_BUF];
396 int tmpvar; 397 int tmpvar;
415/* 416/*
416 * query_weight(object) returns a character pointer to a static buffer 417 * query_weight(object) returns a character pointer to a static buffer
417 * containing the text-representation of the weight of the given object. 418 * containing the text-representation of the weight of the given object.
418 * The buffer will be overwritten by the next call to query_weight(). 419 * The buffer will be overwritten by the next call to query_weight().
419 */ 420 */
420 421const char *
421char *
422query_weight (const object *op) 422query_weight (const object *op)
423{ 423{
424 static char buf[10]; 424 static char buf[10];
425 sint32 i = (op->nrof ? op->nrof : 1) * op->weight + op->carrying; 425 sint32 i = (op->nrof ? op->nrof : 1) * op->weight + op->carrying;
426 426
427 if (op->weight < 0) 427 if (op->weight < 0)
428 return " "; 428 return " ";
429
429 if (i % 1000) 430 if (i % 1000)
430 sprintf (buf, "%6.1f", i / 1000.0); 431 sprintf (buf, "%6.1f", i / 1000.0);
431 else 432 else
432 sprintf (buf, "%4d ", i / 1000); 433 sprintf (buf, "%4d ", i / 1000);
434
433 return buf; 435 return buf;
434} 436}
435 437
436/* 438/*
437 * Returns the pointer to a static buffer containing 439 * Returns the pointer to a static buffer containing
438 * the number requested (of the form first, second, third...) 440 * the number requested (of the form first, second, third...)
439 */ 441 */
440 442const char *
441char *
442get_levelnumber (int i) 443get_levelnumber (int i)
443{ 444{
444 static char buf[MAX_BUF]; 445 static char buf[MAX_BUF];
445 446
446 if (i > 99) 447 if (i > 99)
447 { 448 {
448 sprintf (buf, "%d.", i); 449 sprintf (buf, "%d.", i);
449 return buf; 450 return buf;
450 } 451 }
452
451 if (i < 21) 453 if (i < 21)
452 return levelnumbers[i]; 454 return levelnumbers[i];
453 if (!(i % 10)) 455 if (!(i % 10))
454 return levelnumbers_10[i / 10]; 456 return levelnumbers_10[i / 10];
457
455 strcpy (buf, numbers_10[i / 10]); 458 strcpy (buf, numbers_10[i / 10]);
456 strcat (buf, levelnumbers[i % 10]); 459 strcat (buf, levelnumbers[i % 10]);
457 return buf; 460 return buf;
458} 461}
459
460 462
461/* 463/*
462 * get_number(integer) returns the text-representation of the given number 464 * get_number(integer) returns the text-representation of the given number
463 * in a static buffer. The buffer might be overwritten at the next 465 * in a static buffer. The buffer might be overwritten at the next
464 * call to get_number(). 466 * call to get_number().
465 * It is currently only used by the query_name() function. 467 * It is currently only used by the query_name() function.
466 */ 468 */
467 469const char *
468char *
469get_number (int i) 470get_number (int i)
470{ 471{
471 if (i <= 20) 472 if (i <= 20)
472 return numbers[i]; 473 return numbers[i];
473 else 474 else
490 */ 491 */
491 492
492/* Aug 95 modified this slightly so that Skill tools don't have magic bonus 493/* Aug 95 modified this slightly so that Skill tools don't have magic bonus
493 * from stats.sp - b.t. 494 * from stats.sp - b.t.
494 */ 495 */
495char * 496const char *
496ring_desc (const object *op) 497ring_desc (const object *op)
497{ 498{
498 static char buf[VERY_BIG_BUF]; 499 static char buf[VERY_BIG_BUF];
499 int attr, val, len; 500 int attr, val, len;
500 501
613 case AMULET: 614 case AMULET:
614 case RING: 615 case RING:
615 if (!op->title) 616 if (!op->title)
616 { 617 {
617 /* If ring has a title, full description isn't so useful */ 618 /* If ring has a title, full description isn't so useful */
618 char *s = ring_desc (op); 619 const char *s = ring_desc (op);
619 620
620 if (s[0]) 621 if (s[0])
621 { 622 {
622 safe_strcat (buf, " ", &len, HUGE_BUF); 623 safe_strcat (buf, " ", &len, HUGE_BUF);
623 safe_strcat (buf, s, &len, HUGE_BUF); 624 safe_strcat (buf, s, &len, HUGE_BUF);
643 * overwritten. This may be a bad thing (it may be easier to assume the value 644 * overwritten. This may be a bad thing (it may be easier to assume the value
644 * returned is good forever.) However, it makes printing statements that 645 * returned is good forever.) However, it makes printing statements that
645 * use several names much easier (don't need to store them to temp variables.) 646 * use several names much easier (don't need to store them to temp variables.)
646 * 647 *
647 */ 648 */
648char * 649const char *
649query_name (const object *op) 650query_name (const object *op)
650{ 651{
651 static char buf[5][HUGE_BUF]; 652 static char buf[5][HUGE_BUF]; // OMFG
652 static int use_buf = 0; 653 static int use_buf = 0;
653 int len = 0; 654 int len = 0;
654 655
655#ifdef NEW_MATERIAL_CODE 656#ifdef NEW_MATERIAL_CODE
656 materialtype_t *mt; 657 materialtype_t *mt;
683 if (QUERY_FLAG (op, FLAG_DAMNED)) 684 if (QUERY_FLAG (op, FLAG_DAMNED))
684 safe_strcat (buf[use_buf], " (damned)", &len, HUGE_BUF); 685 safe_strcat (buf[use_buf], " (damned)", &len, HUGE_BUF);
685 else if (QUERY_FLAG (op, FLAG_CURSED)) 686 else if (QUERY_FLAG (op, FLAG_CURSED))
686 safe_strcat (buf[use_buf], " (cursed)", &len, HUGE_BUF); 687 safe_strcat (buf[use_buf], " (cursed)", &len, HUGE_BUF);
687 } 688 }
689
688 /* Basically, if the object is known magical (detect magic spell on it), 690 /* Basically, if the object is known magical (detect magic spell on it),
689 * and it isn't identified, print out the fact that 691 * and it isn't identified, print out the fact that
690 * it is magical. Assume that the detect magical spell will only set 692 * it is magical. Assume that the detect magical spell will only set
691 * KNOWN_MAGICAL if the item actually is magical. 693 * KNOWN_MAGICAL if the item actually is magical.
692 * 694 *
708 710
709 if (QUERY_FLAG (op, FLAG_APPLIED)) 711 if (QUERY_FLAG (op, FLAG_APPLIED))
710 { 712 {
711 switch (op->type) 713 switch (op->type)
712 { 714 {
713 case BOW: 715 case BOW:
714 case WAND: 716 case WAND:
715 case ROD: 717 case ROD:
716 case HORN: 718 case HORN:
717 safe_strcat (buf[use_buf], " (readied)", &len, HUGE_BUF); 719 safe_strcat (buf[use_buf], " (readied)", &len, HUGE_BUF);
718 break; 720 break;
719 case WEAPON: 721 case WEAPON:
720 safe_strcat (buf[use_buf], " (wielded)", &len, HUGE_BUF); 722 safe_strcat (buf[use_buf], " (wielded)", &len, HUGE_BUF);
721 break; 723 break;
722 case ARMOUR: 724 case ARMOUR:
723 case HELMET: 725 case HELMET:
724 case SHIELD: 726 case SHIELD:
725 case RING: 727 case RING:
726 case BOOTS: 728 case BOOTS:
727 case GLOVES: 729 case GLOVES:
728 case AMULET: 730 case AMULET:
729 case GIRDLE: 731 case GIRDLE:
730 case BRACERS: 732 case BRACERS:
731 case CLOAK: 733 case CLOAK:
732 safe_strcat (buf[use_buf], " (worn)", &len, HUGE_BUF); 734 safe_strcat (buf[use_buf], " (worn)", &len, HUGE_BUF);
733 break; 735 break;
734 case CONTAINER: 736 case CONTAINER:
735 safe_strcat (buf[use_buf], " (active)", &len, HUGE_BUF); 737 safe_strcat (buf[use_buf], " (active)", &len, HUGE_BUF);
736 break; 738 break;
737 case SKILL: 739 case SKILL:
738 default: 740 default:
739 safe_strcat (buf[use_buf], " (applied)", &len, HUGE_BUF); 741 safe_strcat (buf[use_buf], " (applied)", &len, HUGE_BUF);
740 } 742 }
741 } 743 }
744
742 if (QUERY_FLAG (op, FLAG_UNPAID)) 745 if (QUERY_FLAG (op, FLAG_UNPAID))
743 safe_strcat (buf[use_buf], " (unpaid)", &len, HUGE_BUF); 746 safe_strcat (buf[use_buf], " (unpaid)", &len, HUGE_BUF);
744 747
745 return buf[use_buf]; 748 return buf [use_buf];
746} 749}
747 750
748/* 751/*
749 * query_base_name(object) returns a character pointer pointing to a static 752 * query_base_name(object) returns a character pointer pointing to a static
750 * buffer which contains a verbose textual representation of the name 753 * buffer which contains a verbose textual representation of the name
784 } 787 }
785 else 788 else
786 { 789 {
787#endif 790#endif
788 if (!plural) 791 if (!plural)
789 strcpy (buf, op->name); 792 assign (buf, op->name);
790 else 793 else
791 strcpy (buf, op->name_pl); 794 assign (buf, op->name_pl);
795
792 len = strlen (buf); 796 len = strlen (buf);
793#ifdef NEW_MATERIAL_CODE 797#ifdef NEW_MATERIAL_CODE
794 } 798 }
795#endif 799#endif
796 800
800 safe_strcat (buf, op->title, &len, MAX_BUF); 804 safe_strcat (buf, op->title, &len, MAX_BUF);
801 } 805 }
802 806
803 switch (op->type) 807 switch (op->type)
804 { 808 {
805 case SPELLBOOK: 809 case SPELLBOOK:
806 case SCROLL: 810 case SCROLL:
807 case WAND: 811 case WAND:
808 case ROD: 812 case ROD:
809 if (QUERY_FLAG (op, FLAG_IDENTIFIED) || QUERY_FLAG (op, FLAG_BEEN_APPLIED)) 813 if (QUERY_FLAG (op, FLAG_IDENTIFIED) || QUERY_FLAG (op, FLAG_BEEN_APPLIED))
810 { 814 {
811 if (!op->title) 815 if (!op->title)
812 { 816 {
813 safe_strcat (buf, " of ", &len, MAX_BUF); 817 safe_strcat (buf, " of ", &len, MAX_BUF);
814 if (op->inv) 818 if (op->inv)
815 safe_strcat (buf, op->inv->name, &len, MAX_BUF); 819 safe_strcat (buf, op->inv->name, &len, MAX_BUF);
816 else 820 else
817 LOG (llevError, "Spellbook %s lacks inventory\n", &op->name); 821 LOG (llevError, "Spellbook %s lacks inventory\n", &op->name);
818 } 822 }
819 if (op->type != SPELLBOOK) 823 if (op->type != SPELLBOOK)
820 { 824 {
821 sprintf (buf2, " (lvl %d)", op->level); 825 sprintf (buf2, " (lvl %d)", op->level);
822 safe_strcat (buf, buf2, &len, MAX_BUF); 826 safe_strcat (buf, buf2, &len, MAX_BUF);
823 } 827 }
824 } 828 }
825 break; 829 break;
826 830
827 831
828 case SKILL: 832 case SKILL:
829 case AMULET: 833 case AMULET:
830 case RING: 834 case RING:
831 if (!op->title) 835 if (!op->title)
832 { 836 {
833 /* If ring has a title, full description isn't so useful */ 837 /* If ring has a title, full description isn't so useful */
834 char *s = ring_desc (op); 838 const char *s = ring_desc (op);
835 839
836 if (s[0]) 840 if (s[0])
837 { 841 {
838 safe_strcat (buf, " ", &len, MAX_BUF); 842 safe_strcat (buf, " ", &len, MAX_BUF);
839 safe_strcat (buf, s, &len, MAX_BUF); 843 safe_strcat (buf, s, &len, MAX_BUF);
840 } 844 }
841 } 845 }
842 break; 846 break;
843 default: 847 default:
844 if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED))) 848 if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED)))
845 { 849 {
846 sprintf (buf + strlen (buf), " %+d", op->magic); 850 sprintf (buf + strlen (buf), " %+d", op->magic);
847 } 851 }
848 } 852 }
853
849 return buf; 854 return buf;
850} 855}
851 856
852/* Break this off from describe_item - that function was way 857/* Break this off from describe_item - that function was way
853 * too long, making it difficult to read. This function deals 858 * too long, making it difficult to read. This function deals
854 * with describing the monsters & players abilities. It should only 859 * with describing the monsters & players abilities. It should only
855 * be called with monster & player objects. Returns a description 860 * be called with monster & player objects. Returns a description
856 * in a static buffer. 861 * in a static buffer.
857 */ 862 */
858
859static char * 863static char *
860describe_monster (const object *op) 864describe_monster (const object *op)
861{ 865{
862 char buf[MAX_BUF]; 866 char buf[MAX_BUF];
863 static char retbuf[VERY_BIG_BUF]; 867 static char retbuf[VERY_BIG_BUF];
867 871
868 /* Note that the resolution this provides for players really isn't 872 /* Note that the resolution this provides for players really isn't
869 * very good. Any player with a speed greater than .67 will 873 * very good. Any player with a speed greater than .67 will
870 * fall into the 'lightning fast movement' category. 874 * fall into the 'lightning fast movement' category.
871 */ 875 */
872 if (FABS (op->speed) > MIN_ACTIVE_SPEED) 876 if (op->has_active_speed ())
873 { 877 {
874 switch ((int) ((FABS (op->speed)) * 15)) 878 switch ((int) ((FABS (op->speed)) * 15))
875 { 879 {
876 case 0: 880 case 0:
877 strcat (retbuf, "(very slow movement)"); 881 strcat (retbuf, "(very slow movement)");
933 { 937 {
934 treasure *t; 938 treasure *t;
935 int first = 1; 939 int first = 1;
936 940
937 for (t = op->randomitems->items; t != NULL; t = t->next) 941 for (t = op->randomitems->items; t != NULL; t = t->next)
938 if (t->item && (t->item->clone.type == SPELL)) 942 if (t->item && t->item->clone.type == SPELL)
939 { 943 {
940 if (first) 944 if (first)
941 { 945 {
942 first = 0; 946 first = 0;
943 strcat (retbuf, "(Spell abilities:)"); 947 strcat (retbuf, "(Spell abilities:)");
989 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 993 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
990 if (tmp->type == SKILL && !strcmp (tmp->name, "clawing")) 994 if (tmp->type == SKILL && !strcmp (tmp->name, "clawing"))
991 break; 995 break;
992 996
993 if (tmp && tmp->attacktype != 0) 997 if (tmp && tmp->attacktype != 0)
994 {
995 DESCRIBE_ABILITY (retbuf, tmp->attacktype, "Claws"); 998 { DESCRIBE_ABILITY (retbuf, tmp->attacktype, "Claws") }
996 }
997 else 999 else
998 {
999 DESCRIBE_ABILITY (retbuf, op->attacktype, "Attacks"); 1000 { DESCRIBE_ABILITY (retbuf, op->attacktype, "Attacks") }
1000 }
1001 } 1001 }
1002 else 1002 else
1003 {
1004 DESCRIBE_ABILITY (retbuf, op->attacktype, "Attacks"); 1003 { DESCRIBE_ABILITY (retbuf, op->attacktype, "Attacks") }
1005 } 1004
1006 DESCRIBE_PATH (retbuf, op->path_attuned, "Attuned"); 1005 DESCRIBE_PATH (retbuf, op->path_attuned, "Attuned");
1007 DESCRIBE_PATH (retbuf, op->path_repelled, "Repelled"); 1006 DESCRIBE_PATH (retbuf, op->path_repelled, "Repelled");
1008 DESCRIBE_PATH (retbuf, op->path_denied, "Denied"); 1007 DESCRIBE_PATH (retbuf, op->path_denied, "Denied");
1008
1009 for (i = 0; i < NROFATTACKS; i++) 1009 for (i = 0; i < NROFATTACKS; i++)
1010 {
1011 if (op->resist[i]) 1010 if (op->resist[i])
1012 { 1011 {
1013 sprintf (buf, "(%s %+d)", resist_plus[i], op->resist[i]); 1012 sprintf (buf, "(%s %+d)", resist_plus[i], op->resist[i]);
1014 strcat (retbuf, buf); 1013 strcat (retbuf, buf);
1015 } 1014 }
1016 } 1015
1017 return retbuf; 1016 return retbuf;
1018} 1017}
1019 1018
1020 1019
1021/* 1020/*
1042 * 1041 *
1043 * Add 'owner' who is the person examining this object. 1042 * Add 'owner' who is the person examining this object.
1044 * owner can be null if no one is being associated with this 1043 * owner can be null if no one is being associated with this
1045 * item (eg, debug dump or the like) 1044 * item (eg, debug dump or the like)
1046 */ 1045 */
1047 1046const char *
1048char *
1049describe_item (const object *op, object *owner) 1047describe_item (const object *op, object *owner)
1050{ 1048{
1051 char buf[MAX_BUF]; 1049 char buf[MAX_BUF];
1052 static char retbuf[VERY_BIG_BUF]; 1050 static char retbuf[VERY_BIG_BUF];
1053 int identified, i; 1051 int identified, i;
1363 } 1361 }
1364 1362
1365 return retbuf; 1363 return retbuf;
1366} 1364}
1367 1365
1366std::string
1367object::describe_item (object *who)
1368{
1369 return std::string (::describe_item (this, who));
1370}
1371
1368/* Return true if the item is magical. A magical item is one that 1372/* Return true if the item is magical. A magical item is one that
1369 * increases/decreases any abilities, provides a resistance, 1373 * increases/decreases any abilities, provides a resistance,
1370 * has a generic magical bonus, or is an artifact. 1374 * has a generic magical bonus, or is an artifact.
1371 * This function is used by detect_magic to determine if an item 1375 * This function is used by detect_magic to determine if an item
1372 * should be marked as magical. 1376 * should be marked as magical.
1523 } 1527 }
1524 } 1528 }
1525 1529
1526 /* If the object is on a map, make sure we update its face */ 1530 /* If the object is on a map, make sure we update its face */
1527 if (op->map) 1531 if (op->map)
1528 update_object (op, UP_OBJ_FACE); 1532 update_object (op, UP_OBJ_CHANGE);
1529 else 1533 else
1530 { 1534 {
1531 pl = op->in_player (); 1535 pl = op->in_player ();
1532 if (pl) 1536 if (pl)
1533 /* A lot of the values can change from an update - might as well send 1537 /* A lot of the values can change from an update - might as well send

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines