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.86 by root, Fri Apr 30 20:43:17 2010 UTC vs.
Revision 1.98 by root, Wed Nov 16 23:41:59 2016 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,2013,2014,2015,2016 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},
353 if (op->flag [FLAG_MAKE_INVIS ]) enc += 1; 342 if (op->flag [FLAG_MAKE_INVIS ]) enc += 1;
354 343
355 return get_power_from_ench (enc); 344 return get_power_from_ench (enc);
356} 345}
357 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
358/* 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
359 * isn't one, returns NULL */ 364 * isn't one, returns NULL */
360const typedata * 365const typedata *
361get_typedata (int itemtype) 366get_typedata (int itemtype)
362{ 367{
363 for (int i = 0; i < item_types_size; i++) 368 return get_typedata_ (itemtype);
364 if (item_types[i].number == itemtype)
365 return &item_types[i];
366
367 return NULL;
368} 369}
369 370
370/* 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
371 * 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
372 * one return NULL */ 373 * one return NULL */
475 */ 476 */
476static const char * 477static const char *
477ring_desc (const object *op) 478ring_desc (const object *op)
478{ 479{
479 static dynbuf_text buf; buf.clear (); 480 static dynbuf_text buf; buf.clear ();
480 int attr, val, len; 481 int attr, val;
481 482
482 if (op->flag [FLAG_IDENTIFIED]) 483 if (op->flag [FLAG_IDENTIFIED])
483 { 484 {
484 for (attr = 0; attr < NUM_STATS; attr++) 485 for (attr = 0; attr < NUM_STATS; attr++)
485 if ((val = op->stats.stat (attr))) 486 if ((val = op->stats.stat (attr)))
486 buf.printf ("(%s%+d)", short_stat_name[attr], val); 487 buf.printf ("(%s%+d)", short_stat_name[attr], val);
487 488
488 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);
489 if (op->stats.wc) buf.printf ("(wc%+d)", op->stats.wc); 490 if (op->stats.wc) buf.printf ("(wc%+d)", op->stats.wc);
490 if (op->stats.dam) buf.printf ("(dam%+d)", op->stats.dam); 491 if (op->stats.dam) buf.printf ("(dam%+d)", op->stats.dam);
491 if (op->stats.ac) buf.printf ("(ac%+d)", op->stats.ac); 492 if (op->stats.ac) buf.printf ("(ac%+d)", op->stats.ac);
492 493
493 buf << describe_resistance (op, 0); 494 buf << describe_resistance (op, 0);
619 * It is also used by examine/ex and similar functions. 620 * It is also used by examine/ex and similar functions.
620 */ 621 */
621const char * 622const char *
622query_name (const object *op) 623query_name (const object *op)
623{ 624{
624 int len = 0;
625 static dynbuf_text bufs[5]; 625 static dynbuf_text bufs[5];
626 static int use_buf = 0; 626 static int use_buf = 0;
627 627
628 use_buf++; 628 use_buf++;
629 use_buf %= 5; 629 use_buf %= 5;
674 674
675 if (op->flag [FLAG_APPLIED]) 675 if (op->flag [FLAG_APPLIED])
676 { 676 {
677 switch (op->type) 677 switch (op->type)
678 { 678 {
679 case RANGED:
679 case BOW: 680 case BOW:
680 case WAND: 681 case WAND:
681 case ROD: 682 case ROD:
682 case HORN: 683 case HORN:
683 buf << " (applied)";
684 break;
685 case WEAPON: 684 case WEAPON:
686 buf << " (applied)"; 685 buf << " (applied)";
687 break; 686 break;
688 case ARMOUR: 687 case ARMOUR:
689 case HELMET: 688 case HELMET:
979 if (!identified) 978 if (!identified)
980 buf << "(unidentified)"; 979 buf << "(unidentified)";
981 980
982 switch (op->type) 981 switch (op->type)
983 { 982 {
983 case RANGED:
984 case BOW: 984 case BOW:
985 case ARROW: 985 case ARROW:
986 case WAND: 986 case WAND:
987 case ROD: 987 case ROD:
988 case HORN: 988 case HORN:
1009 buf.printf ("(capacity %dk; it is ", op->stats.maxsp / 1000); 1009 buf.printf ("(capacity %dk; it is ", op->stats.maxsp / 1000);
1010 } 1010 }
1011 else 1011 else
1012 buf.printf ("(capacity %d; it is ", op->stats.maxsp); 1012 buf.printf ("(capacity %d; it is ", op->stats.maxsp);
1013 1013
1014 i = (op->stats.sp * 10) / op->stats.maxsp; 1014 i = op->stats.sp * 10 / max (op->stats.maxsp, 1);
1015 if (op->stats.sp == 0) 1015
1016 buf << "empty"; 1016 if (op->stats.sp == 0) buf << "empty";
1017 else if (i == 0) 1017 else if (i <= 0) buf << "almost empty";
1018 buf << "almost empty"; 1018 else if (i <= 2) buf << "partially filled";
1019 else if (i < 3) 1019 else if (i <= 5) buf << "half full";
1020 buf << "partially filled"; 1020 else if (i <= 8) buf << "well charged";
1021 else if (i < 6)
1022 buf << "half full";
1023 else if (i < 9)
1024 buf << "well charged";
1025 else if (op->stats.sp == op->stats.maxsp) 1021 else if (op->stats.sp < op->stats.maxsp) buf << "almost full";
1026 buf << "fully charged"; 1022 else buf << "fully charged";
1027 else
1028 buf << "almost full";
1029 1023
1030 buf << ')'; 1024 buf << ')';
1031 break; 1025 break;
1032 1026
1033 case LAMP: 1027 case LAMP:
1093 /* Down here, we more further describe equipment type items. 1087 /* Down here, we more further describe equipment type items.
1094 * only describe them if they have been identified or the like. 1088 * only describe them if they have been identified or the like.
1095 */ 1089 */
1096 if (identified || op->flag [FLAG_BEEN_APPLIED]) 1090 if (identified || op->flag [FLAG_BEEN_APPLIED])
1097 { 1091 {
1098 int attr, val;
1099
1100 for (attr = 0; attr < NUM_STATS; attr++) 1092 for (int attr = 0; attr < NUM_STATS; attr++)
1101 if ((val = op->stats.stat (attr))) 1093 if (int val = op->stats.stat (attr))
1102 buf.printf ("(%s%+d)", short_stat_name[attr], val); 1094 buf.printf ("(%s%+d)", short_stat_name[attr], val);
1103 1095
1104 if (op->stats.exp) 1096 if (op->stats.exp)
1105 buf.printf ("(speed %+lld)", (long long) op->stats.exp); 1097 buf.printf ("(speed %+lld)", (long long) op->stats.exp);
1106 1098
1107 switch (op->type) 1099 switch (op->type)
1108 { 1100 {
1101 case RANGED:
1109 case BOW: 1102 case BOW:
1110 case ARROW: 1103 case ARROW:
1111 case GIRDLE: 1104 case GIRDLE:
1112 case HELMET: 1105 case HELMET:
1113 case SHIELD: 1106 case SHIELD:
1156 { 1149 {
1157 int more_info = 0; 1150 int more_info = 0;
1158 1151
1159 switch (op->type) 1152 switch (op->type)
1160 { 1153 {
1154 case RANGED:
1161 case ROD: /* These use stats.sp for spell selection and stats.food */ 1155 case ROD: /* These use stats.sp for spell selection and stats.food */
1162 case HORN: /* and stats.hp for spell-point regeneration... */ 1156 case HORN: /* and stats.hp for spell-point regeneration... */
1163 case BOW: 1157 case BOW:
1164 case ARROW: 1158 case ARROW:
1165 case WAND: 1159 case WAND:
1352 else if (inv 1346 else if (inv
1353 && inv->msg 1347 && inv->msg
1354 && inv->type == SPELL 1348 && inv->type == SPELL
1355 && flag [FLAG_IDENTIFIED] 1349 && flag [FLAG_IDENTIFIED]
1356 && (type == SPELLBOOK || type == ROD || type == WAND 1350 && (type == SPELLBOOK || type == ROD || type == WAND
1357 || type == ROD || type == POTION || type == SCROLL)) 1351 || type == POTION || type == SCROLL))
1358 // for spellbooks and other stuff that contains spells, print the spell message, 1352 // for spellbooks and other stuff that contains spells, print the spell message,
1359 // unless the object has a custom message handled above. 1353 // unless the object has a custom message handled above.
1360 buf << '\r' << inv->msg << '\n'; 1354 buf << '\r' << inv->msg << '\n';
1361 1355
1362 // try to display the duration for some potions and scrolls 1356 // try to display the duration for some potions and scrolls

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines