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,2011 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> |
… | |
… | |
74 | }; |
74 | }; |
75 | |
75 | |
76 | /* The following is a large table of item types, the fields are: |
76 | /* The following is a large table of item types, the fields are: |
77 | * item number, item name, item name (plural), and two numbers that are the skills |
77 | * item number, item name, item name (plural), and two numbers that are the skills |
78 | * used to identify them. Anytime a new item type is added or removed, this list |
78 | * used to identify them. Anytime a new item type is added or removed, this list |
79 | * should be altered to reflect that. The defines for the numerical values are in |
79 | * should be altered to reflect that. The defines for the numerical values are in |
80 | * define.h |
80 | * define.h |
81 | */ |
81 | */ |
82 | static const typedata item_types[] = { |
82 | static const typedata item_types[] = { |
83 | {PLAYER, "player", "players", 0, 0}, |
83 | {PLAYER, "player", "players", 0, 0}, |
84 | {ROD, "rod", "rods", SK_THAUMATURGY, 0}, |
84 | {ROD, "rod", "rods", SK_THAUMATURGY, 0}, |
85 | {TREASURE, "treasure", "treasure", 0, 0}, |
85 | {TREASURE, "treasure", "treasure", 0, 0}, |
… | |
… | |
146 | {INORGANIC, "inorganic", "inorganics", SK_ALCHEMY, 0}, |
146 | {INORGANIC, "inorganic", "inorganics", SK_ALCHEMY, 0}, |
147 | {SKILL_TOOL, "skill tool", "skill tools", 0, 0}, |
147 | {SKILL_TOOL, "skill tool", "skill tools", 0, 0}, |
148 | {LIGHTER, "lighter", "lighters", 0, 0}, |
148 | {LIGHTER, "lighter", "lighters", 0, 0}, |
149 | {BUILDABLE_WALL, "buildable wall", "buildable walls", 0, 0}, |
149 | {BUILDABLE_WALL, "buildable wall", "buildable walls", 0, 0}, |
150 | {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}, |
151 | {LAMP, "lamp", "lamps", 0, 0}, |
152 | {LAMP, "lamp", "lamps", 0, 0}, |
152 | {DUPLICATOR, "duplicator", "duplicators", 0, 0}, |
153 | {DUPLICATOR, "duplicator", "duplicators", 0, 0}, |
153 | {SPELLBOOK, "spellbook", "spellbooks", SK_LITERACY, 0}, |
154 | {SPELLBOOK, "spellbook", "spellbooks", SK_LITERACY, 0}, |
154 | {CLOAK, "cloak", "cloaks", SK_SMITHERY, 0}, |
155 | {CLOAK, "cloak", "cloaks", SK_SMITHERY, 0}, |
155 | {SPINNER, "spinner", "spinners", 0, 0}, |
156 | {SPINNER, "spinner", "spinners", 0, 0}, |
… | |
… | |
279 | enc += op->stats.stat (i); |
280 | enc += op->stats.stat (i); |
280 | |
281 | |
281 | /* This protection logic is pretty flawed. 20% fire resistance |
282 | /* This protection logic is pretty flawed. 20% fire resistance |
282 | * is much more valuable than 20% confusion, or 20% slow, or |
283 | * is much more valuable than 20% confusion, or 20% slow, or |
283 | * several others. Start at 1 - ignore physical - all that normal |
284 | * several others. Start at 1 - ignore physical - all that normal |
284 | * armour shouldn't be counted against |
285 | * armour shouldn't be counted against |
285 | */ |
286 | */ |
286 | tmp = 0; |
287 | tmp = 0; |
287 | for (i = 1; i < NROFATTACKS; i++) |
288 | for (i = 1; i < NROFATTACKS; i++) |
288 | tmp += op->resist[i]; |
289 | tmp += op->resist[i]; |
289 | |
290 | |
… | |
… | |
357 | { |
358 | { |
358 | return data [itemtype]; |
359 | return data [itemtype]; |
359 | } |
360 | } |
360 | } get_typedata_; |
361 | } get_typedata_; |
361 | |
362 | |
362 | /* 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 |
363 | * isn't one, returns NULL */ |
364 | * isn't one, returns NULL */ |
364 | const typedata * |
365 | const typedata * |
365 | get_typedata (int itemtype) |
366 | get_typedata (int itemtype) |
366 | { |
367 | { |
367 | return get_typedata_ (itemtype); |
368 | return get_typedata_ (itemtype); |
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 */ |
373 | const typedata * |
374 | const typedata * |
374 | get_typedata_by_name (const char *name) |
375 | get_typedata_by_name (const char *name) |
375 | { |
376 | { |
… | |
… | |
475 | */ |
476 | */ |
476 | static const char * |
477 | static const char * |
477 | ring_desc (const object *op) |
478 | ring_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))) |
… | |
… | |
513 | |
514 | |
514 | return buf; |
515 | return buf; |
515 | } |
516 | } |
516 | |
517 | |
517 | /* |
518 | /* |
518 | * query_short_name(object) is similar to query_name, but doesn't |
519 | * query_short_name(object) is similar to query_name, but doesn't |
519 | * contain any information about object status (worn/cursed/etc.) |
520 | * contain any information about object status (worn/cursed/etc.) |
520 | * |
521 | * |
521 | * It is sometimes used when printing messages, so should fit well into a sentence. |
522 | * It is sometimes used when printing messages, so should fit well into a sentence. |
522 | */ |
523 | */ |
523 | const char * |
524 | const char * |
… | |
… | |
619 | * It is also used by examine/ex and similar functions. |
620 | * It is also used by examine/ex and similar functions. |
620 | */ |
621 | */ |
621 | const char * |
622 | const char * |
622 | query_name (const object *op) |
623 | query_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; |
… | |
… | |
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: |
… | |
… | |
1198 | |
1192 | |
1199 | if (more_info) |
1193 | if (more_info) |
1200 | { |
1194 | { |
1201 | if (op->stats.food) buf.printf ("(sustenance%+d)", op->stats.food); |
1195 | if (op->stats.food) buf.printf ("(sustenance%+d)", op->stats.food); |
1202 | if (op->stats.grace) buf.printf ("(grace%+d)", op->stats.grace); |
1196 | if (op->stats.grace) buf.printf ("(grace%+d)", op->stats.grace); |
1203 | if (op->stats.sp) buf.printf ("(magic%+d)", op->stats.sp); |
1197 | if (op->stats.sp) buf.printf ("(magic%+d)", op->stats.sp); |
1204 | if (op->stats.hp) buf.printf ("(regeneration%+d)", op->stats.hp); |
1198 | if (op->stats.hp) buf.printf ("(regeneration%+d)", op->stats.hp); |
1205 | } |
1199 | } |
1206 | |
1200 | |
1207 | if (op->stats.luck) |
1201 | if (op->stats.luck) |
1208 | buf.printf ("(luck%+d)", op->stats.luck); |
1202 | buf.printf ("(luck%+d)", op->stats.luck); |
… | |
… | |
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 |
… | |
… | |
1417 | op->contr->infobox (MSG_CHANNEL ("examine"), info.c_str ()); |
1411 | op->contr->infobox (MSG_CHANNEL ("examine"), info.c_str ()); |
1418 | } |
1412 | } |
1419 | |
1413 | |
1420 | /* |
1414 | /* |
1421 | * inventory prints object's inventory. If inv==NULL then print player's |
1415 | * inventory prints object's inventory. If inv==NULL then print player's |
1422 | * inventory. |
1416 | * inventory. |
1423 | * [ Only items which are applied are showed. Tero.Haatanen@lut.fi ] |
1417 | * [ Only items which are applied are showed. Tero.Haatanen@lut.fi ] |
1424 | */ |
1418 | */ |
1425 | const char * |
1419 | const char * |
1426 | object::query_inventory (object *who, const char *indent) |
1420 | object::query_inventory (object *who, const char *indent) |
1427 | { |
1421 | { |