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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009 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 | * Deliantra 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 |
… | |
… | |
252 | }; |
252 | }; |
253 | |
253 | |
254 | int |
254 | int |
255 | get_power_from_ench (int ench) |
255 | get_power_from_ench (int ench) |
256 | { |
256 | { |
257 | if (ench < 0) ench = 0; |
|
|
258 | if (ench > 20) ench = 20; |
|
|
259 | |
|
|
260 | return enc_to_item_power[ench]; |
257 | return enc_to_item_power [clamp (ench, 0, 20)]; |
261 | } |
258 | } |
262 | |
259 | |
263 | /* This takes an object 'op' and figures out what its item_power |
260 | /* This takes an object 'op' and figures out what its item_power |
264 | * rating should be. This should only really be used by the treasure |
261 | * rating should be. This should only really be used by the treasure |
265 | * generation code, and when loading legacy objects. It returns |
262 | * generation code, and when loading legacy objects. It returns |
… | |
… | |
330 | enc -= 2; |
327 | enc -= 2; |
331 | else if (op->path_repelled & (1 << i)) |
328 | else if (op->path_repelled & (1 << i)) |
332 | enc--; |
329 | enc--; |
333 | } |
330 | } |
334 | |
331 | |
335 | if (QUERY_FLAG (op, FLAG_LIFESAVE)) |
332 | if (op->flag [FLAG_LIFESAVE ]) enc += 5; |
336 | enc += 5; |
333 | if (op->flag [FLAG_REFL_SPELL ]) enc += 3; |
337 | if (QUERY_FLAG (op, FLAG_REFL_SPELL)) |
334 | if (op->flag [FLAG_REFL_MISSILE]) enc += 2; |
338 | enc += 3; |
335 | if (op->flag [FLAG_XRAYS ]) enc += 2; |
339 | if (QUERY_FLAG (op, FLAG_REFL_MISSILE)) |
336 | if (op->flag [FLAG_STEALTH ]) enc += 1; |
340 | enc += 2; |
337 | if (op->flag [FLAG_SEE_IN_DARK ]) enc += 1; |
341 | if (QUERY_FLAG (op, FLAG_STEALTH)) |
338 | if (op->flag [FLAG_MAKE_INVIS ]) enc += 1; |
342 | enc += 1; |
|
|
343 | if (QUERY_FLAG (op, FLAG_XRAYS)) |
|
|
344 | enc += 2; |
|
|
345 | if (QUERY_FLAG (op, FLAG_SEE_IN_DARK)) |
|
|
346 | enc += 1; |
|
|
347 | if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) |
|
|
348 | enc += 1; |
|
|
349 | |
339 | |
350 | return get_power_from_ench (enc); |
340 | return get_power_from_ench (enc); |
351 | } |
341 | } |
352 | |
342 | |
353 | /* returns the typedata that has a number equal to itemtype, if there |
343 | /* returns the typedata that has a number equal to itemtype, if there |
354 | * isn't one, returns NULL */ |
344 | * isn't one, returns NULL */ |
355 | const typedata * |
345 | const typedata * |
356 | get_typedata (int itemtype) |
346 | get_typedata (int itemtype) |
357 | { |
347 | { |
358 | int i; |
|
|
359 | |
|
|
360 | for (i = 0; i < item_types_size; i++) |
348 | for (int i = 0; i < item_types_size; i++) |
361 | if (item_types[i].number == itemtype) |
349 | if (item_types[i].number == itemtype) |
362 | return &item_types[i]; |
350 | return &item_types[i]; |
363 | |
351 | |
364 | return NULL; |
352 | return NULL; |
365 | } |
353 | } |
… | |
… | |
368 | * isn't one, return the plural name that matches, if there still isn't |
356 | * isn't one, return the plural name that matches, if there still isn't |
369 | * one return NULL */ |
357 | * one return NULL */ |
370 | const typedata * |
358 | const typedata * |
371 | get_typedata_by_name (const char *name) |
359 | get_typedata_by_name (const char *name) |
372 | { |
360 | { |
373 | int i; |
|
|
374 | |
|
|
375 | for (i = 0; i < item_types_size; i++) |
361 | for (int i = 0; i < item_types_size; i++) |
376 | if (!strcmp (item_types[i].name, name)) |
362 | if (!strcmp (item_types[i].name, name)) |
377 | return &item_types[i]; |
363 | return &item_types[i]; |
378 | |
364 | |
379 | for (i = 0; i < item_types_size; i++) |
365 | for (int i = 0; i < item_types_size; i++) |
380 | if (!strcmp (item_types[i].name_pl, name)) |
366 | if (!strcmp (item_types[i].name_pl, name)) |
381 | { |
367 | { |
382 | LOG (llevInfo, |
368 | LOG (llevInfo, |
383 | "get_typedata_by_name: I have been sent the plural %s, the singular form %s is prefered\n", name, item_types[i].name); |
369 | "get_typedata_by_name: I have been sent the plural %s, the singular form %s is prefered\n", name, item_types[i].name); |
384 | return &item_types[i]; |
370 | return &item_types[i]; |
385 | } |
371 | } |
386 | |
372 | |
387 | return NULL; |
373 | return 0; |
388 | } |
374 | } |
389 | |
375 | |
390 | /* describe_resistance generates the visible naming for resistances. |
376 | /* describe_resistance generates the visible naming for resistances. |
391 | * returns a static array of the description. This can return |
377 | * returns a static array of the description. This can return |
392 | * a big buffer. |
378 | * a big buffer. |
… | |
… | |
411 | sprintf (buf1, "%s %d\n", resist_plus[tmpvar], op->resist[tmpvar]); |
397 | sprintf (buf1, "%s %d\n", resist_plus[tmpvar], op->resist[tmpvar]); |
412 | |
398 | |
413 | strcat (buf, buf1); |
399 | strcat (buf, buf1); |
414 | } |
400 | } |
415 | } |
401 | } |
|
|
402 | |
416 | return buf; |
403 | return buf; |
417 | } |
404 | } |
418 | |
405 | |
419 | |
406 | |
420 | /* |
407 | /* |
421 | * query_weight(object) returns a character pointer to a static buffer |
408 | * query_weight(object) returns a character pointer to a static buffer |
422 | * containing the text-representation of the weight of the given object. |
409 | * containing the text-representation of the weight of the given object. |
423 | * The buffer will be overwritten by the next call to query_weight(). |
410 | * The buffer will be overwritten by the next call to query_weight(). |
|
|
411 | * |
|
|
412 | * Seems to be used only by unimportant stuff. Remove? |
424 | */ |
413 | */ |
425 | const char * |
414 | const char * |
426 | query_weight (const object *op) |
415 | query_weight (const object *op) |
427 | { |
416 | { |
428 | static char buf[10]; |
417 | static char buf[10]; |
… | |
… | |
454 | return buf; |
443 | return buf; |
455 | } |
444 | } |
456 | |
445 | |
457 | if (i < 21) |
446 | if (i < 21) |
458 | return levelnumbers[i]; |
447 | return levelnumbers[i]; |
|
|
448 | |
459 | if (!(i % 10)) |
449 | if (!(i % 10)) |
460 | return levelnumbers_10[i / 10]; |
450 | return levelnumbers_10[i / 10]; |
461 | |
451 | |
462 | strcpy (buf, numbers_10[i / 10]); |
452 | strcpy (buf, numbers_10[i / 10]); |
463 | strcat (buf, levelnumbers[i % 10]); |
453 | strcat (buf, levelnumbers[i % 10]); |
… | |
… | |
539 | } |
529 | } |
540 | |
530 | |
541 | /* |
531 | /* |
542 | * query_short_name(object) is similar to query_name, but doesn't |
532 | * query_short_name(object) is similar to query_name, but doesn't |
543 | * contain any information about object status (worn/cursed/etc.) |
533 | * contain any information about object status (worn/cursed/etc.) |
|
|
534 | * |
|
|
535 | * It is sometimes used when printing messages, so should fit well into a sentence. |
544 | */ |
536 | */ |
545 | const char * |
537 | const char * |
546 | query_short_name (const object *op) |
538 | query_short_name (const object *op) |
547 | { |
539 | { |
548 | if (op->name == 0) |
540 | if (!op->name) |
549 | return "(null)"; |
541 | return "(null)"; |
550 | |
542 | |
551 | if (!op->nrof |
543 | if (!op->nrof |
552 | && !op->weight |
544 | && !op->weight |
553 | && !op->title |
545 | && !op->title |
… | |
… | |
576 | if (op->type != SPELLBOOK) |
568 | if (op->type != SPELLBOOK) |
577 | buf.printf (" (lvl %d)", op->level); |
569 | buf.printf (" (lvl %d)", op->level); |
578 | } |
570 | } |
579 | break; |
571 | break; |
580 | |
572 | |
581 | case ALTAR: |
573 | case ALTAR: |
582 | case TRIGGER_ALTAR: |
574 | case TRIGGER_ALTAR: |
583 | case IDENTIFY_ALTAR: |
575 | case IDENTIFY_ALTAR: |
584 | case CONVERTER: |
576 | case CONVERTER: |
585 | if (op->slaying == shstr_money) |
577 | if (op->slaying == shstr_money) |
586 | { |
578 | { |
587 | bool wrap = !!buf.size (); |
579 | bool wrap = !!buf.size (); |
588 | |
580 | |
589 | if (wrap) buf << " ["; |
581 | if (wrap) buf << " ["; |
590 | |
582 | |
591 | archetype *coin = 0; |
583 | archetype *coin = 0; |
592 | |
584 | |
593 | for (char const *const *c = coins; *coins; ++c) |
585 | for (char const *const *c = coins; *coins; ++c) |
594 | if ((coin = archetype::find (*c))) |
586 | if ((coin = archetype::find (*c))) |
595 | if (op->stats.food % coin->value == 0) |
587 | if (op->stats.food % coin->value == 0) |
596 | break; |
588 | break; |
597 | |
589 | |
598 | sint32 coins = op->stats.food / coin->value; |
590 | sint32 coins = op->stats.food / coin->value; |
599 | |
591 | |
600 | buf.printf ("drop %d %s (or equivalent)", coins, coins == 1 ? &coin->name : &coin->name_pl); |
592 | buf.printf ("drop %d %s (or equivalent)", coins, coins == 1 ? &coin->name : &coin->name_pl); |
601 | |
593 | |
602 | if (wrap) buf << ']'; |
594 | if (wrap) buf << ']'; |
603 | } |
595 | } |
604 | break; |
596 | break; |
605 | |
597 | |
606 | case SKILL: |
598 | case SKILL: |
607 | case AMULET: |
599 | case AMULET: |
608 | case RING: |
600 | case RING: |
609 | if (!op->title) |
601 | if (!op->title) |
… | |
… | |
632 | * you can make several calls to query_name before the bufs start getting |
624 | * you can make several calls to query_name before the bufs start getting |
633 | * overwritten. This may be a bad thing (it may be easier to assume the value |
625 | * overwritten. This may be a bad thing (it may be easier to assume the value |
634 | * returned is good forever.) However, it makes printing statements that |
626 | * returned is good forever.) However, it makes printing statements that |
635 | * use several names much easier (don't need to store them to temp variables.) |
627 | * use several names much easier (don't need to store them to temp variables.) |
636 | * |
628 | * |
|
|
629 | * It is used extensively within messages, so should return only a prose |
|
|
630 | * and short description of the item. |
637 | */ |
631 | */ |
638 | const char * |
632 | const char * |
639 | query_name (const object *op) |
633 | query_name (const object *op) |
640 | { |
634 | { |
641 | int len = 0; |
635 | int len = 0; |
… | |
… | |
678 | */ |
672 | */ |
679 | if (QUERY_FLAG (op, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (op, FLAG_IDENTIFIED)) |
673 | if (QUERY_FLAG (op, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (op, FLAG_IDENTIFIED)) |
680 | buf << " (magic)"; |
674 | buf << " (magic)"; |
681 | |
675 | |
682 | #if 0 |
676 | #if 0 |
683 | /* item_power will be returned in desribe_item - it shouldn't really |
677 | /* item_power will be returned in describe_item - it shouldn't really |
684 | * be returned in the name. |
678 | * be returned in the name. |
685 | */ |
679 | */ |
686 | if (op->item_power) |
680 | if (op->item_power) |
687 | sprintf (buf[use_buf] + strlen (buf[use_buf]), "(item_power %+d)", op->item_power); |
681 | sprintf (buf[use_buf] + strlen (buf[use_buf]), "(item_power %+d)", op->item_power); |
688 | |
682 | |
… | |
… | |
720 | default: |
714 | default: |
721 | buf << " (applied)"; |
715 | buf << " (applied)"; |
722 | } |
716 | } |
723 | } |
717 | } |
724 | |
718 | |
|
|
719 | switch (op->type) |
|
|
720 | { |
|
|
721 | case LAMP: |
|
|
722 | if (op->glow_radius) |
|
|
723 | buf << " (on)"; |
|
|
724 | else if (op->stats.food <= 0) |
|
|
725 | buf << " (empty)"; |
|
|
726 | else |
|
|
727 | buf << " (off)"; |
|
|
728 | break; |
|
|
729 | |
|
|
730 | case TORCH: |
|
|
731 | if (op->glow_radius) |
|
|
732 | buf << " (burning)"; |
|
|
733 | else if (op->stats.food <= 0) |
|
|
734 | buf << " (burned out)"; |
|
|
735 | break; |
|
|
736 | } |
|
|
737 | |
725 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
738 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
726 | buf << " (unpaid)"; |
739 | buf << " (unpaid)"; |
727 | |
740 | |
728 | return buf; |
741 | return buf; |
729 | } |
742 | } |
… | |
… | |
734 | * of the given object. The buffer will be overwritten at the next |
747 | * of the given object. The buffer will be overwritten at the next |
735 | * call to query_base_name(). This is a lot like query_name, but we |
748 | * call to query_base_name(). This is a lot like query_name, but we |
736 | * don't include the item count or item status. Used for inventory sorting |
749 | * don't include the item count or item status. Used for inventory sorting |
737 | * and sending to client. |
750 | * and sending to client. |
738 | * If plural is set, we generate the plural name of this. |
751 | * If plural is set, we generate the plural name of this. |
|
|
752 | * |
|
|
753 | * It is sometimes used to display messages, and usually only used to match stuff, |
|
|
754 | * so maybe this function should be removed. |
739 | */ |
755 | */ |
740 | const char * |
756 | const char * |
741 | query_base_name (const object *op, int plural) |
757 | query_base_name (const object *op, int plural) |
742 | { |
758 | { |
743 | if ((!plural && !op->name) || (plural && !op->name_pl)) |
759 | if ((!plural && !op->name) || (plural && !op->name_pl)) |
… | |
… | |
813 | */ |
829 | */ |
814 | if (op->has_active_speed ()) |
830 | if (op->has_active_speed ()) |
815 | switch ((int) ((FABS (op->speed)) * 15)) |
831 | switch ((int) ((FABS (op->speed)) * 15)) |
816 | { |
832 | { |
817 | case 0: |
833 | case 0: |
818 | buf << "(very slow movement"; |
834 | buf << "(very slow movement)"; |
819 | break; |
835 | break; |
820 | case 1: |
836 | case 1: |
821 | buf << "(slow movement)"; |
837 | buf << "(slow movement)"; |
822 | break; |
838 | break; |
823 | case 2: |
839 | case 2: |
… | |
… | |
938 | * wouldn't need to use the SEE_INVISIBLE flag to know it is |
954 | * wouldn't need to use the SEE_INVISIBLE flag to know it is |
939 | * a dragon player examining food. Could have things like |
955 | * a dragon player examining food. Could have things like |
940 | * a dwarven axe, in which the full abilities are only known to |
956 | * a dwarven axe, in which the full abilities are only known to |
941 | * dwarves, etc. |
957 | * dwarves, etc. |
942 | * |
958 | * |
943 | * This function is really much more complicated than it should |
|
|
944 | * be, because different objects have different meanings |
|
|
945 | * for the same field (eg, wands use 'food' for charges). This |
|
|
946 | * means these special cases need to be worked out. |
|
|
947 | * |
|
|
948 | * Add 'owner' who is the person examining this object. |
959 | * Add 'owner' who is the person examining this object. |
949 | * owner can be null if no one is being associated with this |
960 | * owner can be null if no one is being associated with this |
950 | * item (eg, debug dump or the like) |
961 | * item (eg, debug dump or the like) |
951 | */ |
962 | */ |
952 | const char * |
963 | const char * |
… | |
… | |
1010 | buf << "well charged."; |
1021 | buf << "well charged."; |
1011 | else if (op->stats.sp == op->stats.maxsp) |
1022 | else if (op->stats.sp == op->stats.maxsp) |
1012 | buf << "fully charged."; |
1023 | buf << "fully charged."; |
1013 | else |
1024 | else |
1014 | buf << "almost full."; |
1025 | buf << "almost full."; |
|
|
1026 | break; |
|
|
1027 | |
|
|
1028 | case LAMP: |
|
|
1029 | { |
|
|
1030 | int percent = ((double) 100 / op->arch->stats.food) * op->stats.food; |
|
|
1031 | buf << "(fuel: "; |
|
|
1032 | if (percent == 0) |
|
|
1033 | buf << "empty"; |
|
|
1034 | else if (percent < 10) |
|
|
1035 | buf << "very low"; |
|
|
1036 | else if (percent < 25) |
|
|
1037 | buf << "low"; |
|
|
1038 | else if (percent < 50) |
|
|
1039 | buf << "half empty"; |
|
|
1040 | else if (percent < 75) |
|
|
1041 | buf << "half full"; |
|
|
1042 | else if (percent < 95) |
|
|
1043 | buf << "well filled"; |
|
|
1044 | else if (percent <= 100) |
|
|
1045 | buf << "full"; |
|
|
1046 | buf << ")"; |
|
|
1047 | } |
1015 | break; |
1048 | break; |
1016 | |
1049 | |
1017 | case FOOD: |
1050 | case FOOD: |
1018 | case FLESH: |
1051 | case FLESH: |
1019 | case DRINK: |
1052 | case DRINK: |
… | |
… | |
1175 | if (QUERY_FLAG (op, FLAG_STEALTH)) buf << "(stealth)"; |
1208 | if (QUERY_FLAG (op, FLAG_STEALTH)) buf << "(stealth)"; |
1176 | |
1209 | |
1177 | if (op->slaying && op->type != FOOD) |
1210 | if (op->slaying && op->type != FOOD) |
1178 | buf.printf ("(slay %s)", &op->slaying); |
1211 | buf.printf ("(slay %s)", &op->slaying); |
1179 | |
1212 | |
|
|
1213 | if (op->type == SKILL_TOOL && op->skill) buf.printf ("(%s)", &op->skill); |
|
|
1214 | |
1180 | buf.add_abilities ("Attacks", op->attacktype); |
1215 | buf.add_abilities ("Attacks", op->attacktype); |
1181 | /* resistance on flesh is only visible for quetzals. If |
1216 | /* resistance on flesh is only visible for quetzals. If |
1182 | * non flesh, everyone can see its resistances |
1217 | * non flesh, everyone can see its resistances |
1183 | */ |
1218 | */ |
1184 | if (op->type != FLESH || (owner && is_dragon_pl (owner))) |
1219 | if (op->type != FLESH || (owner && is_dragon_pl (owner))) |
… | |
… | |
1200 | |
1235 | |
1201 | void |
1236 | void |
1202 | examine (object *op, object *tmp) |
1237 | examine (object *op, object *tmp) |
1203 | { |
1238 | { |
1204 | std::string info = tmp->describe (op); |
1239 | std::string info = tmp->describe (op); |
|
|
1240 | |
1205 | op->contr->infobox (MSG_CHANNEL ("examine"), info.c_str ()); |
1241 | op->contr->infobox (MSG_CHANNEL ("examine"), info.c_str ()); |
1206 | } |
1242 | } |
1207 | |
1243 | |
1208 | /* |
1244 | /* |
1209 | * inventory prints object's inventory. If inv==NULL then print player's |
1245 | * inventory prints object's inventory. If inv==NULL then print player's |
… | |
… | |
1215 | { |
1251 | { |
1216 | static dynbuf_text buf; buf.clear (); |
1252 | static dynbuf_text buf; buf.clear (); |
1217 | |
1253 | |
1218 | for (object *tmp = inv; tmp; tmp = tmp->below) |
1254 | for (object *tmp = inv; tmp; tmp = tmp->below) |
1219 | if (who && QUERY_FLAG (who, FLAG_WIZ)) |
1255 | 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)); |
1256 | buf.printf ("%s- %-28.28s (%5d) %-8s\n", indent, tmp->query_name (), tmp->count, tmp->query_weight ()); |
1221 | else if (!tmp->invisible && (type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED))) |
1257 | 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)); |
1258 | buf.printf ("%s- %-36.36s %-8s\n", indent, tmp->query_name (), tmp->query_weight ()); |
1223 | |
1259 | |
1224 | if (buf.size ()) |
1260 | if (buf.size ()) |
1225 | buf.printf ("%s(total weight: %s)\n", indent, query_weight (this)); |
1261 | buf.printf ("%s(total weight: %s)\n", indent, query_weight ()); |
1226 | else |
1262 | else |
1227 | buf.printf ("%s(empty)\n", indent); |
1263 | buf.printf ("%s(empty)\n", indent); |
1228 | |
1264 | |
1229 | return buf; |
1265 | return buf; |
1230 | } |
1266 | } |
… | |
… | |
1386 | } |
1422 | } |
1387 | |
1423 | |
1388 | /* If the object is on a map, make sure we update its face */ |
1424 | /* If the object is on a map, make sure we update its face */ |
1389 | if (op->map) |
1425 | if (op->map) |
1390 | update_object (op, UP_OBJ_CHANGE); |
1426 | update_object (op, UP_OBJ_CHANGE); |
|
|
1427 | |
1391 | else if (object *pl = op->visible_to ()) |
1428 | if (object *pl = op->visible_to ()) |
1392 | /* A lot of the values can change from an update - might as well send |
1429 | /* A lot of the values can change from an update - might as well send |
1393 | * it all. |
1430 | * it all. |
1394 | */ |
1431 | */ |
1395 | esrv_send_item (pl, op); |
1432 | esrv_send_item (pl, op); |
1396 | } |
1433 | } |