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 |
… | |
… | |
299 | if (op->type == WEAPON) |
296 | if (op->type == WEAPON) |
300 | { |
297 | { |
301 | for (i = 1; i < NROFATTACKS; i++) |
298 | for (i = 1; i < NROFATTACKS; i++) |
302 | if (op->attacktype & (1 << i)) |
299 | if (op->attacktype & (1 << i)) |
303 | enc++; |
300 | enc++; |
|
|
301 | |
304 | if (op->slaying) |
302 | if (op->slaying) |
305 | enc += 2; /* What it slays is probably more relevent */ |
303 | enc += 2; /* What it slays is probably more relevent */ |
306 | } |
304 | } |
|
|
305 | |
307 | /* Items the player can equip */ |
306 | /* Items the player can equip */ |
308 | if ((op->type == WEAPON) || (op->type == ARMOUR) || (op->type == HELMET) || |
307 | if ((op->type == WEAPON) || (op->type == ARMOUR) || (op->type == HELMET) || |
309 | (op->type == SHIELD) || (op->type == RING) || |
308 | (op->type == SHIELD) || (op->type == RING) || |
310 | (op->type == BOOTS) || (op->type == GLOVES) || |
309 | (op->type == BOOTS) || (op->type == GLOVES) || |
311 | (op->type == AMULET) || (op->type == GIRDLE) || (op->type == BRACERS) || (op->type == CLOAK)) |
310 | (op->type == AMULET) || (op->type == GIRDLE) || (op->type == BRACERS) || (op->type == CLOAK)) |
… | |
… | |
314 | enc += op->stats.hp; /* hp regen */ |
313 | enc += op->stats.hp; /* hp regen */ |
315 | enc += op->stats.sp; /* mana regen */ |
314 | enc += op->stats.sp; /* mana regen */ |
316 | enc += op->stats.grace; /* grace regen */ |
315 | enc += op->stats.grace; /* grace regen */ |
317 | enc += op->stats.exp; /* speed bonus */ |
316 | enc += op->stats.exp; /* speed bonus */ |
318 | } |
317 | } |
|
|
318 | |
319 | enc += op->stats.luck; |
319 | enc += op->stats.luck; |
320 | |
320 | |
321 | /* Do spell paths now */ |
321 | /* Do spell paths now */ |
322 | for (i = 1; i < NRSPELLPATHS; i++) |
322 | for (i = 1; i < NRSPELLPATHS; i++) |
323 | { |
323 | { |
… | |
… | |
355 | int i; |
355 | int i; |
356 | |
356 | |
357 | for (i = 0; i < item_types_size; i++) |
357 | for (i = 0; i < item_types_size; i++) |
358 | if (item_types[i].number == itemtype) |
358 | if (item_types[i].number == itemtype) |
359 | return &item_types[i]; |
359 | return &item_types[i]; |
|
|
360 | |
360 | return NULL; |
361 | return NULL; |
361 | } |
362 | } |
362 | |
363 | |
363 | /* returns the typedata that has a name equal to itemtype, if there |
364 | /* returns the typedata that has a name equal to itemtype, if there |
364 | * isn't one, return the plural name that matches, if there still isn't |
365 | * isn't one, return the plural name that matches, if there still isn't |
… | |
… | |
369 | int i; |
370 | int i; |
370 | |
371 | |
371 | for (i = 0; i < item_types_size; i++) |
372 | for (i = 0; i < item_types_size; i++) |
372 | if (!strcmp (item_types[i].name, name)) |
373 | if (!strcmp (item_types[i].name, name)) |
373 | return &item_types[i]; |
374 | return &item_types[i]; |
|
|
375 | |
374 | for (i = 0; i < item_types_size; i++) |
376 | for (i = 0; i < item_types_size; i++) |
375 | if (!strcmp (item_types[i].name_pl, name)) |
377 | if (!strcmp (item_types[i].name_pl, name)) |
376 | { |
378 | { |
377 | LOG (llevInfo, |
379 | LOG (llevInfo, |
378 | "get_typedata_by_name: I have been sent the plural %s, the singular form %s is preffered\n", name, item_types[i].name); |
380 | "get_typedata_by_name: I have been sent the plural %s, the singular form %s is prefered\n", name, item_types[i].name); |
379 | return &item_types[i]; |
381 | return &item_types[i]; |
380 | } |
382 | } |
|
|
383 | |
381 | return NULL; |
384 | return NULL; |
382 | } |
385 | } |
383 | |
386 | |
384 | /* describe_resistance generates the visible naming for resistances. |
387 | /* describe_resistance generates the visible naming for resistances. |
385 | * returns a static array of the description. This can return |
388 | * returns a static array of the description. This can return |
… | |
… | |
537 | * contain any information about object status (worn/cursed/etc.) |
540 | * contain any information about object status (worn/cursed/etc.) |
538 | */ |
541 | */ |
539 | const char * |
542 | const char * |
540 | query_short_name (const object *op) |
543 | query_short_name (const object *op) |
541 | { |
544 | { |
542 | if (op->name == 0) |
545 | if (!op->name) |
543 | return "(null)"; |
546 | return "(null)"; |
544 | |
547 | |
545 | if (!op->nrof |
548 | if (!op->nrof |
546 | && !op->weight |
549 | && !op->weight |
547 | && !op->title |
550 | && !op->title |
… | |
… | |
570 | if (op->type != SPELLBOOK) |
573 | if (op->type != SPELLBOOK) |
571 | buf.printf (" (lvl %d)", op->level); |
574 | buf.printf (" (lvl %d)", op->level); |
572 | } |
575 | } |
573 | break; |
576 | break; |
574 | |
577 | |
575 | case ALTAR: |
578 | case ALTAR: |
576 | case TRIGGER_ALTAR: |
579 | case TRIGGER_ALTAR: |
577 | case IDENTIFY_ALTAR: |
580 | case IDENTIFY_ALTAR: |
578 | case CONVERTER: |
581 | case CONVERTER: |
579 | if (op->slaying == shstr_money) |
582 | if (op->slaying == shstr_money) |
580 | { |
583 | { |
581 | bool wrap = !!buf.size (); |
584 | bool wrap = !!buf.size (); |
582 | |
585 | |
583 | if (wrap) buf << " ["; |
586 | if (wrap) buf << " ["; |
584 | |
587 | |
585 | archetype *coin = 0; |
588 | archetype *coin = 0; |
586 | |
589 | |
587 | for (char const *const *c = coins; *coins; ++c) |
590 | for (char const *const *c = coins; *coins; ++c) |
588 | if ((coin = archetype::find (*c))) |
591 | if ((coin = archetype::find (*c))) |
589 | if (op->stats.food % coin->value == 0) |
592 | if (op->stats.food % coin->value == 0) |
590 | break; |
593 | break; |
591 | |
594 | |
592 | sint32 coins = op->stats.food / coin->value; |
595 | sint32 coins = op->stats.food / coin->value; |
593 | |
596 | |
594 | buf.printf ("drop %d %s (or equivalent)", coins, coins == 1 ? &coin->name : &coin->name_pl); |
597 | buf.printf ("drop %d %s (or equivalent)", coins, coins == 1 ? &coin->name : &coin->name_pl); |
595 | |
598 | |
596 | if (wrap) buf << ']'; |
599 | if (wrap) buf << ']'; |
597 | } |
600 | } |
598 | break; |
601 | break; |
599 | |
602 | |
600 | case SKILL: |
603 | case SKILL: |
601 | case AMULET: |
604 | case AMULET: |
602 | case RING: |
605 | case RING: |
603 | if (!op->title) |
606 | if (!op->title) |
… | |
… | |
714 | default: |
717 | default: |
715 | buf << " (applied)"; |
718 | buf << " (applied)"; |
716 | } |
719 | } |
717 | } |
720 | } |
718 | |
721 | |
|
|
722 | switch (op->type) |
|
|
723 | { |
|
|
724 | case LAMP: |
|
|
725 | if (op->glow_radius) |
|
|
726 | buf << " (on)"; |
|
|
727 | else if (op->stats.food <= 0) |
|
|
728 | buf << " (empty)"; |
|
|
729 | else |
|
|
730 | buf << " (off)"; |
|
|
731 | break; |
|
|
732 | |
|
|
733 | case TORCH: |
|
|
734 | if (op->glow_radius) |
|
|
735 | buf << " (burning)"; |
|
|
736 | else if (op->stats.food <= 0) |
|
|
737 | buf << " (burned out)"; |
|
|
738 | break; |
|
|
739 | } |
|
|
740 | |
719 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
741 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
720 | buf << " (unpaid)"; |
742 | buf << " (unpaid)"; |
721 | |
743 | |
722 | return buf; |
744 | return buf; |
723 | } |
745 | } |
… | |
… | |
807 | */ |
829 | */ |
808 | if (op->has_active_speed ()) |
830 | if (op->has_active_speed ()) |
809 | switch ((int) ((FABS (op->speed)) * 15)) |
831 | switch ((int) ((FABS (op->speed)) * 15)) |
810 | { |
832 | { |
811 | case 0: |
833 | case 0: |
812 | buf << "(very slow movement"; |
834 | buf << "(very slow movement)"; |
813 | break; |
835 | break; |
814 | case 1: |
836 | case 1: |
815 | buf << "(slow movement)"; |
837 | buf << "(slow movement)"; |
816 | break; |
838 | break; |
817 | case 2: |
839 | case 2: |
… | |
… | |
1006 | buf << "fully charged."; |
1028 | buf << "fully charged."; |
1007 | else |
1029 | else |
1008 | buf << "almost full."; |
1030 | buf << "almost full."; |
1009 | break; |
1031 | break; |
1010 | |
1032 | |
|
|
1033 | case LAMP: |
|
|
1034 | { |
|
|
1035 | int percent = ((double) 100 / op->arch->stats.food) * op->stats.food; |
|
|
1036 | buf << "(fuel: "; |
|
|
1037 | if (percent == 0) |
|
|
1038 | buf << "empty"; |
|
|
1039 | else if (percent < 10) |
|
|
1040 | buf << "very low"; |
|
|
1041 | else if (percent < 25) |
|
|
1042 | buf << "low"; |
|
|
1043 | else if (percent < 50) |
|
|
1044 | buf << "half empty"; |
|
|
1045 | else if (percent < 75) |
|
|
1046 | buf << "half full"; |
|
|
1047 | else if (percent < 95) |
|
|
1048 | buf << "well filled"; |
|
|
1049 | else if (percent <= 100) |
|
|
1050 | buf << "full"; |
|
|
1051 | buf << ")"; |
|
|
1052 | } |
|
|
1053 | break; |
|
|
1054 | |
1011 | case FOOD: |
1055 | case FOOD: |
1012 | case FLESH: |
1056 | case FLESH: |
1013 | case DRINK: |
1057 | case DRINK: |
1014 | if (identified || QUERY_FLAG (op, FLAG_BEEN_APPLIED)) |
1058 | if (identified || QUERY_FLAG (op, FLAG_BEEN_APPLIED)) |
1015 | { |
1059 | { |
… | |
… | |
1209 | { |
1253 | { |
1210 | static dynbuf_text buf; buf.clear (); |
1254 | static dynbuf_text buf; buf.clear (); |
1211 | |
1255 | |
1212 | for (object *tmp = inv; tmp; tmp = tmp->below) |
1256 | for (object *tmp = inv; tmp; tmp = tmp->below) |
1213 | if (who && QUERY_FLAG (who, FLAG_WIZ)) |
1257 | if (who && QUERY_FLAG (who, FLAG_WIZ)) |
1214 | buf.printf ("%s- %-28.28s (%5d) %-8s\n", indent, query_name (tmp), tmp->count, query_weight (tmp)); |
1258 | buf.printf ("%s- %-28.28s (%5d) %-8s\n", indent, tmp->query_name (), tmp->count, tmp->query_weight ()); |
1215 | else if (!tmp->invisible && (type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED))) |
1259 | else if (!tmp->invisible && (type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED))) |
1216 | buf.printf ("%s- %-36.36s %-8s\n", indent, query_name (tmp), query_weight (tmp)); |
1260 | buf.printf ("%s- %-36.36s %-8s\n", indent, tmp->query_name (), tmp->query_weight ()); |
1217 | |
1261 | |
1218 | if (buf.size ()) |
1262 | if (buf.size ()) |
1219 | buf.printf ("%s(total weight: %s)\n", indent, query_weight (this)); |
1263 | buf.printf ("%s(total weight: %s)\n", indent, query_weight ()); |
1220 | else |
1264 | else |
1221 | buf.printf ("%s(empty)\n", indent); |
1265 | buf.printf ("%s(empty)\n", indent); |
1222 | |
1266 | |
1223 | return buf; |
1267 | return buf; |
1224 | } |
1268 | } |
… | |
… | |
1380 | } |
1424 | } |
1381 | |
1425 | |
1382 | /* If the object is on a map, make sure we update its face */ |
1426 | /* If the object is on a map, make sure we update its face */ |
1383 | if (op->map) |
1427 | if (op->map) |
1384 | update_object (op, UP_OBJ_CHANGE); |
1428 | update_object (op, UP_OBJ_CHANGE); |
|
|
1429 | |
1385 | else if (object *pl = op->visible_to ()) |
1430 | if (object *pl = op->visible_to ()) |
1386 | /* A lot of the values can change from an update - might as well send |
1431 | /* A lot of the values can change from an update - might as well send |
1387 | * it all. |
1432 | * it all. |
1388 | */ |
1433 | */ |
1389 | esrv_send_item (pl, op); |
1434 | esrv_send_item (pl, op); |
1390 | } |
1435 | } |