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.89 by root, Sat May 15 23:41:05 2010 UTC vs.
Revision 1.100 by root, Sat Nov 17 23:40:00 2018 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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * 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 6 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 9 * 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 10 * 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 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the Affero GNU General Public License 19 * 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 20 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25#include <global.h> 26#include <global.h>
26#include <living.h> 27#include <living.h>
49 * Basically, for the use/nonuse, the code does something like: 50 * 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 51 * "This item goes %s\n", with the use/nonuse values filling in the %s
51 */ 52 */
52// see include/object.h 53// see include/object.h
53Body_Locations body_locations[NUM_BODY_LOCATIONS] = { 54Body_Locations body_locations[NUM_BODY_LOCATIONS] = {
54 {KW_body_skill , "You can use it as your skill" , "It is used as a skill"}, 55# 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"}, 56# include "slotinc.h"
56 {KW_body_range , "You can use it as your range weapon" , "It is used as a range weapon"}, 57# 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}; 58};
70 59
71static char numbers_10[10][20] = { 60static char numbers_10[10][20] = {
72 "zero", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", 61 "zero", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy",
73 "eighty", "ninety" 62 "eighty", "ninety"
86}; 75};
87 76
88/* The following is a large table of item types, the fields are: 77/* The following is a large table of item types, the fields are:
89 * item number, item name, item name (plural), and two numbers that are the skills 78 * item number, item name, item name (plural), and two numbers that are the skills
90 * used to identify them. Anytime a new item type is added or removed, this list 79 * used to identify them. Anytime a new item type is added or removed, this list
91 * should be altered to reflect that. The defines for the numerical values are in 80 * should be altered to reflect that. The defines for the numerical values are in
92 * define.h 81 * define.h
93 */ 82 */
94static const typedata item_types[] = { 83static const typedata item_types[] = {
95 {PLAYER, "player", "players", 0, 0}, 84 {PLAYER, "player", "players", 0, 0},
96 {ROD, "rod", "rods", SK_THAUMATURGY, 0}, 85 {ROD, "rod", "rods", SK_THAUMATURGY, 0},
97 {TREASURE, "treasure", "treasure", 0, 0}, 86 {TREASURE, "treasure", "treasure", 0, 0},
158 {INORGANIC, "inorganic", "inorganics", SK_ALCHEMY, 0}, 147 {INORGANIC, "inorganic", "inorganics", SK_ALCHEMY, 0},
159 {SKILL_TOOL, "skill tool", "skill tools", 0, 0}, 148 {SKILL_TOOL, "skill tool", "skill tools", 0, 0},
160 {LIGHTER, "lighter", "lighters", 0, 0}, 149 {LIGHTER, "lighter", "lighters", 0, 0},
161 {BUILDABLE_WALL, "buildable wall", "buildable walls", 0, 0}, 150 {BUILDABLE_WALL, "buildable wall", "buildable walls", 0, 0},
162 {MISC_OBJECT, "bric-a-brac", "bric-a-brac", 0, 0}, 151 {MISC_OBJECT, "bric-a-brac", "bric-a-brac", 0, 0},
152 {TORCH, "torch", "torches", 0, 0},
163 {LAMP, "lamp", "lamps", 0, 0}, 153 {LAMP, "lamp", "lamps", 0, 0},
164 {DUPLICATOR, "duplicator", "duplicators", 0, 0}, 154 {DUPLICATOR, "duplicator", "duplicators", 0, 0},
165 {SPELLBOOK, "spellbook", "spellbooks", SK_LITERACY, 0}, 155 {SPELLBOOK, "spellbook", "spellbooks", SK_LITERACY, 0},
166 {CLOAK, "cloak", "cloaks", SK_SMITHERY, 0}, 156 {CLOAK, "cloak", "cloaks", SK_SMITHERY, 0},
167 {SPINNER, "spinner", "spinners", 0, 0}, 157 {SPINNER, "spinner", "spinners", 0, 0},
291 enc += op->stats.stat (i); 281 enc += op->stats.stat (i);
292 282
293 /* This protection logic is pretty flawed. 20% fire resistance 283 /* This protection logic is pretty flawed. 20% fire resistance
294 * is much more valuable than 20% confusion, or 20% slow, or 284 * is much more valuable than 20% confusion, or 20% slow, or
295 * several others. Start at 1 - ignore physical - all that normal 285 * several others. Start at 1 - ignore physical - all that normal
296 * armour shouldn't be counted against 286 * armour shouldn't be counted against
297 */ 287 */
298 tmp = 0; 288 tmp = 0;
299 for (i = 1; i < NROFATTACKS; i++) 289 for (i = 1; i < NROFATTACKS; i++)
300 tmp += op->resist[i]; 290 tmp += op->resist[i];
301 291
369 { 359 {
370 return data [itemtype]; 360 return data [itemtype];
371 } 361 }
372} get_typedata_; 362} get_typedata_;
373 363
374/* returns the typedata that has a number equal to itemtype, if there 364/* returns the typedata that has a number equal to itemtype, if there
375 * isn't one, returns NULL */ 365 * isn't one, returns NULL */
376const typedata * 366const typedata *
377get_typedata (int itemtype) 367get_typedata (int itemtype)
378{ 368{
379 return get_typedata_ (itemtype); 369 return get_typedata_ (itemtype);
380} 370}
381 371
382/* returns the typedata that has a name equal to itemtype, if there 372/* returns the typedata that has a name equal to itemtype, if there
383 * isn't one, return the plural name that matches, if there still isn't 373 * isn't one, return the plural name that matches, if there still isn't
384 * one return NULL */ 374 * one return NULL */
385const typedata * 375const typedata *
386get_typedata_by_name (const char *name) 376get_typedata_by_name (const char *name)
387{ 377{
487 */ 477 */
488static const char * 478static const char *
489ring_desc (const object *op) 479ring_desc (const object *op)
490{ 480{
491 static dynbuf_text buf; buf.clear (); 481 static dynbuf_text buf; buf.clear ();
492 int attr, val, len; 482 int attr, val;
493 483
494 if (op->flag [FLAG_IDENTIFIED]) 484 if (op->flag [FLAG_IDENTIFIED])
495 { 485 {
496 for (attr = 0; attr < NUM_STATS; attr++) 486 for (attr = 0; attr < NUM_STATS; attr++)
497 if ((val = op->stats.stat (attr))) 487 if ((val = op->stats.stat (attr)))
525 515
526 return buf; 516 return buf;
527} 517}
528 518
529/* 519/*
530 * query_short_name(object) is similar to query_name, but doesn't 520 * query_short_name(object) is similar to query_name, but doesn't
531 * contain any information about object status (worn/cursed/etc.) 521 * contain any information about object status (worn/cursed/etc.)
532 * 522 *
533 * It is sometimes used when printing messages, so should fit well into a sentence. 523 * It is sometimes used when printing messages, so should fit well into a sentence.
534 */ 524 */
535const char * 525const char *
631 * It is also used by examine/ex and similar functions. 621 * It is also used by examine/ex and similar functions.
632 */ 622 */
633const char * 623const char *
634query_name (const object *op) 624query_name (const object *op)
635{ 625{
636 int len = 0;
637 static dynbuf_text bufs[5]; 626 static dynbuf_text bufs[5];
638 static int use_buf = 0; 627 static int use_buf = 0;
639 628
640 use_buf++; 629 use_buf++;
641 use_buf %= 5; 630 use_buf %= 5;
1021 buf.printf ("(capacity %dk; it is ", op->stats.maxsp / 1000); 1010 buf.printf ("(capacity %dk; it is ", op->stats.maxsp / 1000);
1022 } 1011 }
1023 else 1012 else
1024 buf.printf ("(capacity %d; it is ", op->stats.maxsp); 1013 buf.printf ("(capacity %d; it is ", op->stats.maxsp);
1025 1014
1026 i = (op->stats.sp * 10) / op->stats.maxsp; 1015 i = op->stats.sp * 10 / max (op->stats.maxsp, 1);
1027 if (op->stats.sp == 0) 1016
1028 buf << "empty"; 1017 if (op->stats.sp == 0) buf << "empty";
1029 else if (i == 0) 1018 else if (i <= 0) buf << "almost empty";
1030 buf << "almost empty"; 1019 else if (i <= 2) buf << "partially filled";
1031 else if (i < 3) 1020 else if (i <= 5) buf << "half full";
1032 buf << "partially filled"; 1021 else if (i <= 8) buf << "well charged";
1033 else if (i < 6)
1034 buf << "half full";
1035 else if (i < 9)
1036 buf << "well charged";
1037 else if (op->stats.sp == op->stats.maxsp) 1022 else if (op->stats.sp < op->stats.maxsp) buf << "almost full";
1038 buf << "fully charged"; 1023 else buf << "fully charged";
1039 else
1040 buf << "almost full";
1041 1024
1042 buf << ')'; 1025 buf << ')';
1043 break; 1026 break;
1044 1027
1045 case LAMP: 1028 case LAMP:
1210 1193
1211 if (more_info) 1194 if (more_info)
1212 { 1195 {
1213 if (op->stats.food) buf.printf ("(sustenance%+d)", op->stats.food); 1196 if (op->stats.food) buf.printf ("(sustenance%+d)", op->stats.food);
1214 if (op->stats.grace) buf.printf ("(grace%+d)", op->stats.grace); 1197 if (op->stats.grace) buf.printf ("(grace%+d)", op->stats.grace);
1215 if (op->stats.sp) buf.printf ("(magic%+d)", op->stats.sp); 1198 if (op->stats.sp) buf.printf ("(magic%+d)", op->stats.sp);
1216 if (op->stats.hp) buf.printf ("(regeneration%+d)", op->stats.hp); 1199 if (op->stats.hp) buf.printf ("(regeneration%+d)", op->stats.hp);
1217 } 1200 }
1218 1201
1219 if (op->stats.luck) 1202 if (op->stats.luck)
1220 buf.printf ("(luck%+d)", op->stats.luck); 1203 buf.printf ("(luck%+d)", op->stats.luck);
1364 else if (inv 1347 else if (inv
1365 && inv->msg 1348 && inv->msg
1366 && inv->type == SPELL 1349 && inv->type == SPELL
1367 && flag [FLAG_IDENTIFIED] 1350 && flag [FLAG_IDENTIFIED]
1368 && (type == SPELLBOOK || type == ROD || type == WAND 1351 && (type == SPELLBOOK || type == ROD || type == WAND
1369 || type == ROD || type == POTION || type == SCROLL)) 1352 || type == POTION || type == SCROLL))
1370 // for spellbooks and other stuff that contains spells, print the spell message, 1353 // for spellbooks and other stuff that contains spells, print the spell message,
1371 // unless the object has a custom message handled above. 1354 // unless the object has a custom message handled above.
1372 buf << '\r' << inv->msg << '\n'; 1355 buf << '\r' << inv->msg << '\n';
1373 1356
1374 // try to display the duration for some potions and scrolls 1357 // try to display the duration for some potions and scrolls
1429 op->contr->infobox (MSG_CHANNEL ("examine"), info.c_str ()); 1412 op->contr->infobox (MSG_CHANNEL ("examine"), info.c_str ());
1430} 1413}
1431 1414
1432/* 1415/*
1433 * inventory prints object's inventory. If inv==NULL then print player's 1416 * inventory prints object's inventory. If inv==NULL then print player's
1434 * inventory. 1417 * inventory.
1435 * [ Only items which are applied are showed. Tero.Haatanen@lut.fi ] 1418 * [ Only items which are applied are showed. Tero.Haatanen@lut.fi ]
1436 */ 1419 */
1437const char * 1420const char *
1438object::query_inventory (object *who, const char *indent) 1421object::query_inventory (object *who, const char *indent)
1439{ 1422{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines