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.58 by root, Mon Oct 12 14:00:57 2009 UTC vs.
Revision 1.77 by root, Sat Apr 3 02:27:24 2010 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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 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.
47 * Note that using the term 'human' may not be very accurate, humanoid 47 * Note that using the term 'human' may not be very accurate, humanoid
48 * may be better. 48 * may be better.
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
52Body_Locations body_locations[NUM_BODY_LOCATIONS] = { 53Body_Locations body_locations[NUM_BODY_LOCATIONS] = {
53 {KW_body_skill , "You can use it as your skill" , "It is used as a skill"}, 54 {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_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_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_shield , "You can wield it as a shield" , "It is used as a shield"},
63 {KW_body_foot , "You can put it on your foot" , "It goes on a human's foot"}, 64 {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_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_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 {KW_body_waist , "You can wear it around your waist" , "It goes around a human's waist"},
67/*{"body_dragon_torso", "your body", "a dragon's body"} */ 68/*{"body_dragon_torso", "your body", "a dragon's body"} */
68};
69
70static char numbers[21][20] = {
71 "no", "", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
72 "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
73 "eighteen", "nineteen", "twenty"
74}; 69};
75 70
76static char numbers_10[10][20] = { 71static char numbers_10[10][20] = {
77 "zero", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", 72 "zero", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy",
78 "eighty", "ninety" 73 "eighty", "ninety"
170 {SPELLBOOK, "spellbook", "spellbooks", SK_LITERACY, 0}, 165 {SPELLBOOK, "spellbook", "spellbooks", SK_LITERACY, 0},
171 {CLOAK, "cloak", "cloaks", SK_SMITHERY, 0}, 166 {CLOAK, "cloak", "cloaks", SK_SMITHERY, 0},
172 {SPINNER, "spinner", "spinners", 0, 0}, 167 {SPINNER, "spinner", "spinners", 0, 0},
173 {GATE, "gate", "gates", 0, 0}, 168 {GATE, "gate", "gates", 0, 0},
174 {BUTTON, "button", "buttons", 0, 0}, 169 {BUTTON, "button", "buttons", 0, 0},
175 {CF_HANDLE, "cf handle", "cf handles", 0, 0}, 170 {T_HANDLE, "cf handle", "cf handles", 0, 0},
176 {HOLE, "hole", "holes", 0, 0}, 171 {HOLE, "hole", "holes", 0, 0},
177 {TRAPDOOR, "trapdoor", "trapdoors", 0, 0}, 172 {TRAPDOOR, "trapdoor", "trapdoors", 0, 0},
178 {SIGN, "sign", "signs", 0, 0}, 173 {SIGN, "sign", "signs", 0, 0},
179 {BOOTS, "boots", "boots", SK_SMITHERY, 0}, 174 {BOOTS, "boots", "boots", SK_SMITHERY, 0},
180 {GLOVES, "gloves", "gloves", SK_SMITHERY, 0}, 175 {GLOVES, "gloves", "gloves", SK_SMITHERY, 0},
207 {BUILDER, "item builder", "item builders", 0, 0}, 202 {BUILDER, "item builder", "item builders", 0, 0},
208 {MATERIAL, "building material", "building materials", 0, 0}, 203 {MATERIAL, "building material", "building materials", 0, 0},
209 {ITEM_TRANSFORMER, "item_transformer", "item_transformers", 0, 0}, 204 {ITEM_TRANSFORMER, "item_transformer", "item_transformers", 0, 0},
210}; 205};
211 206
212const int item_types_size = sizeof (item_types) / sizeof (*item_types); 207static const int item_types_size = sizeof (item_types) / sizeof (*item_types);
213
214materialtype_t *materialt;
215
216/*
217materialtype 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 208
239/* 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
240 * 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
241 * wear whatever they want with no worries. Perhaps having the steep 211 * wear whatever they want with no worries. Perhaps having the steep
242 * curve is good (maybe even steeper), but allowing players to 212 * curve is good (maybe even steeper), but allowing players to
319 289
320 enc += op->stats.luck; 290 enc += op->stats.luck;
321 291
322 /* Do spell paths now */ 292 /* Do spell paths now */
323 for (i = 1; i < NRSPELLPATHS; i++) 293 for (i = 1; i < NRSPELLPATHS; i++)
324 {
325 if (op->path_attuned & (1 << i)) 294 if (op->path_attuned & (1 << i))
326 enc++; 295 enc++;
327 else if (op->path_denied & (1 << i)) 296 else if (op->path_denied & (1 << i))
328 enc -= 2; 297 enc -= 2;
329 else if (op->path_repelled & (1 << i)) 298 else if (op->path_repelled & (1 << i))
330 enc--; 299 enc--;
331 }
332 300
333 if (op->flag [FLAG_LIFESAVE ]) enc += 5; 301 if (op->flag [FLAG_LIFESAVE ]) enc += 5;
334 if (op->flag [FLAG_REFL_SPELL ]) enc += 3; 302 if (op->flag [FLAG_REFL_SPELL ]) enc += 3;
335 if (op->flag [FLAG_REFL_MISSILE]) enc += 2; 303 if (op->flag [FLAG_REFL_MISSILE]) enc += 2;
336 if (op->flag [FLAG_XRAYS ]) enc += 2; 304 if (op->flag [FLAG_XRAYS ]) enc += 2;
381 * but do put a newline at the end. Useful when dumping to files 349 * but do put a newline at the end. Useful when dumping to files
382 */ 350 */
383const char * 351const char *
384describe_resistance (const object *op, int newline) 352describe_resistance (const object *op, int newline)
385{ 353{
386 static char buf[VERY_BIG_BUF]; 354 static dynbuf_text buf; buf.clear ();
387 char buf1[VERY_BIG_BUF];
388 int tmpvar;
389 355
390 buf[0] = 0; 356 for (int i = 0; i < NROFATTACKS; i++)
391 for (tmpvar = 0; tmpvar < NROFATTACKS; tmpvar++)
392 {
393 if (op->resist[tmpvar] && (op->type != FLESH || atnr_is_dragon_enabled (tmpvar) == 1)) 357 if (op->resist[i] && (op->type != FLESH || atnr_is_dragon_enabled (i) == 1))
394 { 358 buf.printf (newline ? "%s %d\n" : "(%s %+d)", resist_plus[i], op->resist[i]);
395 if (!newline)
396 sprintf (buf1, "(%s %+d)", resist_plus[tmpvar], op->resist[tmpvar]);
397 else
398 sprintf (buf1, "%s %d\n", resist_plus[tmpvar], op->resist[tmpvar]);
399
400 strcat (buf, buf1);
401 }
402 }
403 359
404 return buf; 360 return buf;
405} 361}
406
407 362
408/* 363/*
409 * query_weight(object) returns a character pointer to a static buffer 364 * query_weight(object) returns a character pointer to a static buffer
410 * containing the text-representation of the weight of the given object. 365 * containing the text-representation of the weight of the given object.
411 * The buffer will be overwritten by the next call to query_weight(). 366 * The buffer will be overwritten by the next call to query_weight().
451 return levelnumbers_10[i / 10]; 406 return levelnumbers_10[i / 10];
452 407
453 strcpy (buf, numbers_10[i / 10]); 408 strcpy (buf, numbers_10[i / 10]);
454 strcat (buf, levelnumbers[i % 10]); 409 strcat (buf, levelnumbers[i % 10]);
455 return buf; 410 return buf;
456}
457
458/*
459 * get_number(integer) returns the text-representation of the given number
460 * in a static buffer. The buffer might be overwritten at the next
461 * call to get_number().
462 * It is currently only used by the query_name() function.
463 */
464const char *
465get_number (int i)
466{
467 if (i <= 20)
468 return numbers[i];
469 else
470 {
471 static char buf[MAX_BUF];
472
473 sprintf (buf, "%d", i);
474 return buf;
475 }
476} 411}
477 412
478/* 413/*
479 * Returns pointer to static buffer containing ring's or amulet's 414 * Returns pointer to static buffer containing ring's or amulet's
480 * abilities 415 * abilities
486 */ 421 */
487 422
488/* Aug 95 modified this slightly so that Skill tools don't have magic bonus 423/* Aug 95 modified this slightly so that Skill tools don't have magic bonus
489 * from stats.sp - b.t. 424 * from stats.sp - b.t.
490 */ 425 */
491const char * 426static const char *
492ring_desc (const object *op) 427ring_desc (const object *op)
493{ 428{
494 static dynbuf_text buf; buf.clear (); 429 static dynbuf_text buf; buf.clear ();
495 int attr, val, len; 430 int attr, val, len;
496 431
627 * returned is good forever.) However, it makes printing statements that 562 * returned is good forever.) However, it makes printing statements that
628 * use several names much easier (don't need to store them to temp variables.) 563 * use several names much easier (don't need to store them to temp variables.)
629 * 564 *
630 * It is used extensively within messages, so should return only a prose 565 * It is used extensively within messages, so should return only a prose
631 * and short description of the item. 566 * and short description of the item.
567 * It is also used by examine/ex and similar functions.
632 */ 568 */
633const char * 569const char *
634query_name (const object *op) 570query_name (const object *op)
635{ 571{
636 int len = 0; 572 int len = 0;
641 use_buf %= 5; 577 use_buf %= 5;
642 578
643 dynbuf_text &buf = bufs [use_buf]; 579 dynbuf_text &buf = bufs [use_buf];
644 buf.clear (); 580 buf.clear ();
645 581
582#if 0
646 if ((op->is_armor () || op->is_weapon ()) && op->materialname) 583 if ((op->is_armor () || op->is_weapon ()) && op->material)
647 if (materialtype_t *mt = name_to_material (op->materialname))
648 buf << mt->description << ' '; 584 buf << op->material->description << ' ';
585#endif
649 586
650 buf << query_short_name (op); 587 buf << query_short_name (op);
651 588
652 if (QUERY_FLAG (op, FLAG_INV_LOCKED)) 589 if (QUERY_FLAG (op, FLAG_INV_LOCKED))
653 buf << " *"; 590 buf << " *";
654 if (op->type == CONTAINER && ((op->env && op->env->container == op) || (!op->env && QUERY_FLAG (op, FLAG_APPLIED)))) 591 if (op->is_open_container ())
655 buf << " (open)"; 592 buf << " (open)";
656 593
657 if (QUERY_FLAG (op, FLAG_KNOWN_CURSED)) 594 if (QUERY_FLAG (op, FLAG_KNOWN_CURSED))
658 { 595 {
659 if (QUERY_FLAG (op, FLAG_DAMNED)) 596 if (QUERY_FLAG (op, FLAG_DAMNED))
689 { 626 {
690 case BOW: 627 case BOW:
691 case WAND: 628 case WAND:
692 case ROD: 629 case ROD:
693 case HORN: 630 case HORN:
694 buf << (op->env && op->env->current_weapon == op ? " (readied)" : " (applied)"); 631 buf << " (applied)";
695 break; 632 break;
696 case WEAPON: 633 case WEAPON:
697 buf << (op->env && op->env->current_weapon == op ? " (wielded)" : " (applied)"); 634 buf << " (applied)";
698 break; 635 break;
699 case ARMOUR: 636 case ARMOUR:
700 case HELMET: 637 case HELMET:
701 case SHIELD: 638 case SHIELD:
702 case RING: 639 case RING:
751 * and sending to client. 688 * and sending to client.
752 * If plural is set, we generate the plural name of this. 689 * If plural is set, we generate the plural name of this.
753 * 690 *
754 * It is sometimes used to display messages, and usually only used to match stuff, 691 * It is sometimes used to display messages, and usually only used to match stuff,
755 * so maybe this function should be removed. 692 * so maybe this function should be removed.
693 * It is also used for client-side inventory/item descriptions.
756 */ 694 */
757const char * 695const char *
758query_base_name (const object *op, int plural) 696query_base_name (const object *op, int plural)
759{ 697{
760 if ((!plural && !op->name) || (plural && !op->name_pl)) 698 if ((!plural && !op->name) || (plural && !op->name_pl))
761 return "(null)"; 699 return "(null)";
762 700
763 if (!op->nrof && !op->weight && !op->title && !is_magical (op)) 701 if (!op->nrof && !op->weight && !op->title && !is_magical (op)
702 && op->type != EXIT)
764 return op->name; /* To speed things up (or make things slower?) */ 703 return op->name; /* To speed things up (or make things slower?) */
765 704
766 static dynbuf_text buf; buf.clear (); 705 static dynbuf_text buf; buf.clear ();
767 706
707#if 0
768 if ((op->is_armor () || op->is_weapon ()) && op->materialname) 708 if ((op->is_armor () || op->is_weapon ()) && op->material)
769 if (materialtype_t *mt = name_to_material (op->materialname))
770 if (op->arch->materialname != mt->name) 709 if (op->arch->material != op->material)
771 buf << mt->description << ' '; 710 buf << op->material->description << ' ';
711#endif
772 712
773 buf << (plural ? op->name_pl : op->name); 713 buf << (plural ? op->name_pl : op->name);
774 714
775 if (op->title && QUERY_FLAG (op, FLAG_IDENTIFIED)) 715 if (op->title && QUERY_FLAG (op, FLAG_IDENTIFIED))
776 buf << ' ' << op->title; 716 buf << ' ' << op->title;
803 if (s && *s) 743 if (s && *s)
804 buf << ' ' << s; 744 buf << ' ' << s;
805 } 745 }
806 break; 746 break;
807 747
748 case EXIT:
749 // random map exits "unfortunately" get patched, so this only works before entering
750 if (EXIT_PATH (op) == shstr_random_map_exit)
751 buf << " (random map)";
752 else if (!EXIT_PATH (op))
753 buf << " (closed)";
754 break;
755
808 default: 756 default:
809 if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED))) 757 if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED)))
810 buf.printf (" %+d", op->magic); 758 buf.printf (" %+d", op->magic);
811 } 759 }
812 760
827 /* Note that the resolution this provides for players really isn't 775 /* Note that the resolution this provides for players really isn't
828 * very good. Any player with a speed greater than .67 will 776 * very good. Any player with a speed greater than .67 will
829 * fall into the 'lightning fast movement' category. 777 * fall into the 'lightning fast movement' category.
830 */ 778 */
831 if (op->has_active_speed ()) 779 if (op->has_active_speed ())
832 switch ((int) ((FABS (op->speed)) * 15)) 780 switch ((int)(op->speed * 15.))
833 { 781 {
834 case 0: 782 case 0:
835 buf << "(very slow movement)"; 783 buf << "(very slow movement)";
836 break; 784 break;
837 case 1: 785 case 1:
907 if (op->stats.luck) 855 if (op->stats.luck)
908 buf.printf ("(luck%+d)", op->stats.luck); 856 buf.printf ("(luck%+d)", op->stats.luck);
909 } 857 }
910 858
911 /* describe attacktypes */ 859 /* describe attacktypes */
912 if (is_dragon_pl (op)) 860 if (op->is_dragon ())
913 { 861 {
914 /* for dragon players display the attacktypes from clawing skill 862 /* for dragon players display the attacktypes from clawing skill
915 * Break apart the for loop - move the comparison checking down - 863 * Break apart the for loop - move the comparison checking down -
916 * this makes it more readable. 864 * this makes it more readable.
917 */ 865 */
1216 1164
1217 buf.add_abilities ("Attacks", op->attacktype); 1165 buf.add_abilities ("Attacks", op->attacktype);
1218 /* resistance on flesh is only visible for quetzals. If 1166 /* resistance on flesh is only visible for quetzals. If
1219 * non flesh, everyone can see its resistances 1167 * non flesh, everyone can see its resistances
1220 */ 1168 */
1221 if (op->type != FLESH || (owner && is_dragon_pl (owner))) 1169 if (op->type != FLESH || (owner && owner->is_dragon ()))
1222 buf << describe_resistance (op, 0); 1170 buf << describe_resistance (op, 0);
1223 1171
1224 buf.add_paths ("Attuned", op->path_attuned); 1172 buf.add_paths ("Attuned", op->path_attuned);
1225 buf.add_paths ("Repelled", op->path_repelled); 1173 buf.add_paths ("Repelled", op->path_repelled);
1226 buf.add_paths ("Denied", op->path_denied); 1174 buf.add_paths ("Denied", op->path_denied);
1253{ 1201{
1254 static dynbuf_text buf; buf.clear (); 1202 static dynbuf_text buf; buf.clear ();
1255 1203
1256 for (object *tmp = inv; tmp; tmp = tmp->below) 1204 for (object *tmp = inv; tmp; tmp = tmp->below)
1257 if (who && QUERY_FLAG (who, FLAG_WIZ)) 1205 if (who && QUERY_FLAG (who, FLAG_WIZ))
1258 buf.printf ("%s- %-28.28s (%5d) %-8s\n", indent, tmp->query_name (), tmp->count, tmp->query_weight ()); 1206 buf.printf ("%s- %-28.28s %-8s (%9d) %s\n", indent, tmp->query_name (), tmp->query_weight (), tmp->count, tmp->uuid.c_str ());
1259 else if (!tmp->invisible && (type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED))) 1207 else if (!tmp->invisible && (type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED)))
1260 buf.printf ("%s- %-36.36s %-8s\n", indent, tmp->query_name (), tmp->query_weight ()); 1208 buf.printf ("%s- %-36.36s %-8s\n", indent, tmp->query_name (), tmp->query_weight ());
1261 1209
1262 if (buf.size ()) 1210 if (buf.size ())
1263 buf.printf ("%s(total weight: %s)\n", indent, query_weight ()); 1211 buf.printf ("%s(total weight: %s)\n", indent, query_weight ());

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines