1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * 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 |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your 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, |
… | |
… | |
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 GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <funcpoint.h> |
|
|
26 | #include <living.h> |
25 | #include <living.h> |
27 | #include <spells.h> |
26 | #include <spells.h> |
|
|
27 | |
|
|
28 | const char *const coins[NUM_COINS + 1] = { "royalty", "platinacoin", "goldcoin", "silvercoin", 0 }; |
28 | |
29 | |
29 | /* the ordering of this is actually doesn't make a difference |
30 | /* the ordering of this is actually doesn't make a difference |
30 | * However, for ease of use, new entries should go at the end |
31 | * However, for ease of use, new entries should go at the end |
31 | * so those people that debug the code that get used to something |
32 | * so those people that debug the code that get used to something |
32 | * being in the location 4 don't get confused. |
33 | * being in the location 4 don't get confused. |
… | |
… | |
298 | if (op->type == WEAPON) |
299 | if (op->type == WEAPON) |
299 | { |
300 | { |
300 | for (i = 1; i < NROFATTACKS; i++) |
301 | for (i = 1; i < NROFATTACKS; i++) |
301 | if (op->attacktype & (1 << i)) |
302 | if (op->attacktype & (1 << i)) |
302 | enc++; |
303 | enc++; |
|
|
304 | |
303 | if (op->slaying) |
305 | if (op->slaying) |
304 | enc += 2; /* What it slays is probably more relevent */ |
306 | enc += 2; /* What it slays is probably more relevent */ |
305 | } |
307 | } |
|
|
308 | |
306 | /* Items the player can equip */ |
309 | /* Items the player can equip */ |
307 | if ((op->type == WEAPON) || (op->type == ARMOUR) || (op->type == HELMET) || |
310 | if ((op->type == WEAPON) || (op->type == ARMOUR) || (op->type == HELMET) || |
308 | (op->type == SHIELD) || (op->type == RING) || |
311 | (op->type == SHIELD) || (op->type == RING) || |
309 | (op->type == BOOTS) || (op->type == GLOVES) || |
312 | (op->type == BOOTS) || (op->type == GLOVES) || |
310 | (op->type == AMULET) || (op->type == GIRDLE) || (op->type == BRACERS) || (op->type == CLOAK)) |
313 | (op->type == AMULET) || (op->type == GIRDLE) || (op->type == BRACERS) || (op->type == CLOAK)) |
… | |
… | |
313 | enc += op->stats.hp; /* hp regen */ |
316 | enc += op->stats.hp; /* hp regen */ |
314 | enc += op->stats.sp; /* mana regen */ |
317 | enc += op->stats.sp; /* mana regen */ |
315 | enc += op->stats.grace; /* grace regen */ |
318 | enc += op->stats.grace; /* grace regen */ |
316 | enc += op->stats.exp; /* speed bonus */ |
319 | enc += op->stats.exp; /* speed bonus */ |
317 | } |
320 | } |
|
|
321 | |
318 | enc += op->stats.luck; |
322 | enc += op->stats.luck; |
319 | |
323 | |
320 | /* Do spell paths now */ |
324 | /* Do spell paths now */ |
321 | for (i = 1; i < NRSPELLPATHS; i++) |
325 | for (i = 1; i < NRSPELLPATHS; i++) |
322 | { |
326 | { |
… | |
… | |
354 | int i; |
358 | int i; |
355 | |
359 | |
356 | for (i = 0; i < item_types_size; i++) |
360 | for (i = 0; i < item_types_size; i++) |
357 | if (item_types[i].number == itemtype) |
361 | if (item_types[i].number == itemtype) |
358 | return &item_types[i]; |
362 | return &item_types[i]; |
|
|
363 | |
359 | return NULL; |
364 | return NULL; |
360 | } |
365 | } |
361 | |
366 | |
362 | /* returns the typedata that has a name equal to itemtype, if there |
367 | /* returns the typedata that has a name equal to itemtype, if there |
363 | * isn't one, return the plural name that matches, if there still isn't |
368 | * isn't one, return the plural name that matches, if there still isn't |
… | |
… | |
368 | int i; |
373 | int i; |
369 | |
374 | |
370 | for (i = 0; i < item_types_size; i++) |
375 | for (i = 0; i < item_types_size; i++) |
371 | if (!strcmp (item_types[i].name, name)) |
376 | if (!strcmp (item_types[i].name, name)) |
372 | return &item_types[i]; |
377 | return &item_types[i]; |
|
|
378 | |
373 | for (i = 0; i < item_types_size; i++) |
379 | for (i = 0; i < item_types_size; i++) |
374 | if (!strcmp (item_types[i].name_pl, name)) |
380 | if (!strcmp (item_types[i].name_pl, name)) |
375 | { |
381 | { |
376 | LOG (llevInfo, |
382 | LOG (llevInfo, |
377 | "get_typedata_by_name: I have been sent the plural %s, the singular form %s is preffered\n", name, item_types[i].name); |
383 | "get_typedata_by_name: I have been sent the plural %s, the singular form %s is prefered\n", name, item_types[i].name); |
378 | return &item_types[i]; |
384 | return &item_types[i]; |
379 | } |
385 | } |
|
|
386 | |
380 | return NULL; |
387 | return NULL; |
381 | } |
388 | } |
382 | |
389 | |
383 | /* describe_resistance generates the visible naming for resistances. |
390 | /* describe_resistance generates the visible naming for resistances. |
384 | * returns a static array of the description. This can return |
391 | * returns a static array of the description. This can return |
… | |
… | |
417 | */ |
424 | */ |
418 | const char * |
425 | const char * |
419 | query_weight (const object *op) |
426 | query_weight (const object *op) |
420 | { |
427 | { |
421 | static char buf[10]; |
428 | static char buf[10]; |
422 | sint32 i = (op->nrof ? op->nrof : 1) * op->weight + op->carrying; |
429 | sint32 i = op->total_weight (); |
423 | |
430 | |
424 | if (op->weight < 0) |
431 | if (op->weight < 0) |
425 | return " "; |
432 | return " "; |
426 | |
433 | |
427 | if (i % 1000) |
434 | if (i % 1000) |
… | |
… | |
536 | * contain any information about object status (worn/cursed/etc.) |
543 | * contain any information about object status (worn/cursed/etc.) |
537 | */ |
544 | */ |
538 | const char * |
545 | const char * |
539 | query_short_name (const object *op) |
546 | query_short_name (const object *op) |
540 | { |
547 | { |
|
|
548 | if (!op->name) |
|
|
549 | return "(null)"; |
|
|
550 | |
|
|
551 | if (!op->nrof |
|
|
552 | && !op->weight |
|
|
553 | && !op->title |
|
|
554 | && !is_magical (op) |
|
|
555 | && op->slaying != shstr_money) |
|
|
556 | return op->name; /* To speed things up (or make things slower?) */ |
|
|
557 | |
541 | static dynbuf_text buf; buf.clear (); |
558 | static dynbuf_text buf; buf.clear (); |
542 | |
|
|
543 | if (op->name == NULL) |
|
|
544 | return "(null)"; |
|
|
545 | |
|
|
546 | if (!op->nrof && !op->weight && !op->title && !is_magical (op)) |
|
|
547 | return op->name; /* To speed things up (or make things slower?) */ |
|
|
548 | |
559 | |
549 | buf << (op->nrof <= 1 ? op->name : op->name_pl); |
560 | buf << (op->nrof <= 1 ? op->name : op->name_pl); |
550 | |
561 | |
551 | if (op->title && QUERY_FLAG (op, FLAG_IDENTIFIED)) |
562 | if (op->title && QUERY_FLAG (op, FLAG_IDENTIFIED)) |
552 | buf << ' ' << op->title; |
563 | buf << ' ' << op->title; |
… | |
… | |
565 | if (op->type != SPELLBOOK) |
576 | if (op->type != SPELLBOOK) |
566 | buf.printf (" (lvl %d)", op->level); |
577 | buf.printf (" (lvl %d)", op->level); |
567 | } |
578 | } |
568 | break; |
579 | break; |
569 | |
580 | |
|
|
581 | case ALTAR: |
|
|
582 | case TRIGGER_ALTAR: |
|
|
583 | case IDENTIFY_ALTAR: |
|
|
584 | case CONVERTER: |
|
|
585 | if (op->slaying == shstr_money) |
|
|
586 | { |
|
|
587 | bool wrap = !!buf.size (); |
|
|
588 | |
|
|
589 | if (wrap) buf << " ["; |
|
|
590 | |
|
|
591 | archetype *coin = 0; |
|
|
592 | |
|
|
593 | for (char const *const *c = coins; *coins; ++c) |
|
|
594 | if ((coin = archetype::find (*c))) |
|
|
595 | if (op->stats.food % coin->value == 0) |
|
|
596 | break; |
|
|
597 | |
|
|
598 | sint32 coins = op->stats.food / coin->value; |
|
|
599 | |
|
|
600 | buf.printf ("drop %d %s (or equivalent)", coins, coins == 1 ? &coin->name : &coin->name_pl); |
|
|
601 | |
|
|
602 | if (wrap) buf << ']'; |
|
|
603 | } |
|
|
604 | break; |
|
|
605 | |
570 | case SKILL: |
606 | case SKILL: |
571 | case AMULET: |
607 | case AMULET: |
572 | case RING: |
608 | case RING: |
573 | if (!op->title) |
609 | if (!op->title) |
574 | { |
610 | { |
… | |
… | |
577 | |
613 | |
578 | if (s && *s) |
614 | if (s && *s) |
579 | buf << " " << s; |
615 | buf << " " << s; |
580 | } |
616 | } |
581 | break; |
617 | break; |
|
|
618 | |
582 | default: |
619 | default: |
583 | if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED))) |
620 | if (op->magic && ((QUERY_FLAG (op, FLAG_BEEN_APPLIED) && need_identify (op)) || QUERY_FLAG (op, FLAG_IDENTIFIED))) |
584 | buf.printf (" %+d", op->magic); |
621 | buf.printf (" %+d", op->magic); |
585 | } |
622 | } |
586 | |
623 | |
… | |
… | |
776 | */ |
813 | */ |
777 | if (op->has_active_speed ()) |
814 | if (op->has_active_speed ()) |
778 | switch ((int) ((FABS (op->speed)) * 15)) |
815 | switch ((int) ((FABS (op->speed)) * 15)) |
779 | { |
816 | { |
780 | case 0: |
817 | case 0: |
781 | buf << "(very slow movement"; |
818 | buf << "(very slow movement)"; |
782 | break; |
819 | break; |
783 | case 1: |
820 | case 1: |
784 | buf << "(slow movement)"; |
821 | buf << "(slow movement)"; |
785 | break; |
822 | break; |
786 | case 2: |
823 | case 2: |
… | |
… | |
1157 | |
1194 | |
1158 | std::string |
1195 | std::string |
1159 | object::describe_item (object *who) |
1196 | object::describe_item (object *who) |
1160 | { |
1197 | { |
1161 | return std::string (::describe_item (this, who)); |
1198 | return std::string (::describe_item (this, who)); |
|
|
1199 | } |
|
|
1200 | |
|
|
1201 | void |
|
|
1202 | examine (object *op, object *tmp) |
|
|
1203 | { |
|
|
1204 | std::string info = tmp->describe (op); |
|
|
1205 | op->contr->infobox (MSG_CHANNEL ("examine"), info.c_str ()); |
|
|
1206 | } |
|
|
1207 | |
|
|
1208 | /* |
|
|
1209 | * inventory prints object's inventory. If inv==NULL then print player's |
|
|
1210 | * inventory. |
|
|
1211 | * [ Only items which are applied are showed. Tero.Haatanen@lut.fi ] |
|
|
1212 | */ |
|
|
1213 | const char * |
|
|
1214 | object::query_inventory (object *who, const char *indent) |
|
|
1215 | { |
|
|
1216 | static dynbuf_text buf; buf.clear (); |
|
|
1217 | |
|
|
1218 | for (object *tmp = inv; tmp; tmp = tmp->below) |
|
|
1219 | if (who && QUERY_FLAG (who, FLAG_WIZ)) |
|
|
1220 | buf.printf ("%s- %-28.28s (%5d) %-8s\n", indent, query_name (tmp), tmp->count, query_weight (tmp)); |
|
|
1221 | else if (!tmp->invisible && (type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED))) |
|
|
1222 | buf.printf ("%s- %-36.36s %-8s\n", indent, query_name (tmp), query_weight (tmp)); |
|
|
1223 | |
|
|
1224 | if (buf.size ()) |
|
|
1225 | buf.printf ("%s(total weight: %s)\n", indent, query_weight (this)); |
|
|
1226 | else |
|
|
1227 | buf.printf ("%s(empty)\n", indent); |
|
|
1228 | |
|
|
1229 | return buf; |
1162 | } |
1230 | } |
1163 | |
1231 | |
1164 | /* Return true if the item is magical. A magical item is one that |
1232 | /* Return true if the item is magical. A magical item is one that |
1165 | * increases/decreases any abilities, provides a resistance, |
1233 | * increases/decreases any abilities, provides a resistance, |
1166 | * has a generic magical bonus, or is an artifact. |
1234 | * has a generic magical bonus, or is an artifact. |
… | |
… | |
1294 | * Supposed to fix face-values as well here, but later. |
1362 | * Supposed to fix face-values as well here, but later. |
1295 | */ |
1363 | */ |
1296 | void |
1364 | void |
1297 | identify (object *op) |
1365 | identify (object *op) |
1298 | { |
1366 | { |
1299 | object *pl; |
|
|
1300 | |
|
|
1301 | SET_FLAG (op, FLAG_IDENTIFIED); |
1367 | SET_FLAG (op, FLAG_IDENTIFIED); |
1302 | CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); |
1368 | CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); |
1303 | CLEAR_FLAG (op, FLAG_NO_SKILL_IDENT); |
1369 | CLEAR_FLAG (op, FLAG_NO_SKILL_IDENT); |
1304 | |
1370 | |
1305 | /* |
1371 | /* |
… | |
… | |
1312 | { |
1378 | { |
1313 | if (op->inv && op->randomitems) |
1379 | if (op->inv && op->randomitems) |
1314 | op->title = op->inv->name; |
1380 | op->title = op->inv->name; |
1315 | else if (op->arch) |
1381 | else if (op->arch) |
1316 | { |
1382 | { |
1317 | op->name = op->arch->object::name; |
1383 | op->name = op->arch->object::name; |
1318 | op->name_pl = op->arch->object::name_pl; |
1384 | op->name_pl = op->arch->object::name_pl; |
1319 | } |
1385 | } |
1320 | } |
1386 | } |
1321 | |
1387 | |
1322 | /* If the object is on a map, make sure we update its face */ |
1388 | /* If the object is on a map, make sure we update its face */ |
1323 | if (op->map) |
1389 | if (op->map) |
1324 | update_object (op, UP_OBJ_CHANGE); |
1390 | update_object (op, UP_OBJ_CHANGE); |
1325 | else |
1391 | |
1326 | { |
1392 | if (object *pl = op->visible_to ()) |
1327 | pl = op->in_player (); |
|
|
1328 | if (pl) |
|
|
1329 | /* A lot of the values can change from an update - might as well send |
1393 | /* A lot of the values can change from an update - might as well send |
1330 | * it all. |
1394 | * it all. |
1331 | */ |
1395 | */ |
1332 | esrv_send_item (pl, op); |
1396 | esrv_send_item (pl, op); |
1333 | } |
|
|
1334 | } |
1397 | } |
1335 | |
1398 | |