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 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 |
… | |
… | |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
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> |
28 | |
27 | |
29 | const char *const coins[NUM_COINS + 1] = { "royalty", "platinacoin", "goldcoin", "silvercoin", 0 }; |
28 | const char *const coins[NUM_COINS + 1] = { "royalty", "platinacoin", "goldcoin", "silvercoin", 0 }; |
30 | |
29 | |
… | |
… | |
253 | }; |
252 | }; |
254 | |
253 | |
255 | int |
254 | int |
256 | get_power_from_ench (int ench) |
255 | get_power_from_ench (int ench) |
257 | { |
256 | { |
258 | if (ench < 0) ench = 0; |
|
|
259 | if (ench > 20) ench = 20; |
|
|
260 | |
|
|
261 | return enc_to_item_power[ench]; |
257 | return enc_to_item_power [clamp (ench, 0, 20)]; |
262 | } |
258 | } |
263 | |
259 | |
264 | /* 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 |
265 | * 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 |
266 | * generation code, and when loading legacy objects. It returns |
262 | * generation code, and when loading legacy objects. It returns |
… | |
… | |
300 | if (op->type == WEAPON) |
296 | if (op->type == WEAPON) |
301 | { |
297 | { |
302 | for (i = 1; i < NROFATTACKS; i++) |
298 | for (i = 1; i < NROFATTACKS; i++) |
303 | if (op->attacktype & (1 << i)) |
299 | if (op->attacktype & (1 << i)) |
304 | enc++; |
300 | enc++; |
|
|
301 | |
305 | if (op->slaying) |
302 | if (op->slaying) |
306 | enc += 2; /* What it slays is probably more relevent */ |
303 | enc += 2; /* What it slays is probably more relevent */ |
307 | } |
304 | } |
|
|
305 | |
308 | /* Items the player can equip */ |
306 | /* Items the player can equip */ |
309 | if ((op->type == WEAPON) || (op->type == ARMOUR) || (op->type == HELMET) || |
307 | if ((op->type == WEAPON) || (op->type == ARMOUR) || (op->type == HELMET) || |
310 | (op->type == SHIELD) || (op->type == RING) || |
308 | (op->type == SHIELD) || (op->type == RING) || |
311 | (op->type == BOOTS) || (op->type == GLOVES) || |
309 | (op->type == BOOTS) || (op->type == GLOVES) || |
312 | (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)) |
… | |
… | |
315 | enc += op->stats.hp; /* hp regen */ |
313 | enc += op->stats.hp; /* hp regen */ |
316 | enc += op->stats.sp; /* mana regen */ |
314 | enc += op->stats.sp; /* mana regen */ |
317 | enc += op->stats.grace; /* grace regen */ |
315 | enc += op->stats.grace; /* grace regen */ |
318 | enc += op->stats.exp; /* speed bonus */ |
316 | enc += op->stats.exp; /* speed bonus */ |
319 | } |
317 | } |
|
|
318 | |
320 | enc += op->stats.luck; |
319 | enc += op->stats.luck; |
321 | |
320 | |
322 | /* Do spell paths now */ |
321 | /* Do spell paths now */ |
323 | for (i = 1; i < NRSPELLPATHS; i++) |
322 | for (i = 1; i < NRSPELLPATHS; i++) |
324 | { |
323 | { |
… | |
… | |
356 | int i; |
355 | int i; |
357 | |
356 | |
358 | for (i = 0; i < item_types_size; i++) |
357 | for (i = 0; i < item_types_size; i++) |
359 | if (item_types[i].number == itemtype) |
358 | if (item_types[i].number == itemtype) |
360 | return &item_types[i]; |
359 | return &item_types[i]; |
|
|
360 | |
361 | return NULL; |
361 | return NULL; |
362 | } |
362 | } |
363 | |
363 | |
364 | /* 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 |
365 | * 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 |
… | |
… | |
370 | int i; |
370 | int i; |
371 | |
371 | |
372 | for (i = 0; i < item_types_size; i++) |
372 | for (i = 0; i < item_types_size; i++) |
373 | if (!strcmp (item_types[i].name, name)) |
373 | if (!strcmp (item_types[i].name, name)) |
374 | return &item_types[i]; |
374 | return &item_types[i]; |
|
|
375 | |
375 | for (i = 0; i < item_types_size; i++) |
376 | for (i = 0; i < item_types_size; i++) |
376 | if (!strcmp (item_types[i].name_pl, name)) |
377 | if (!strcmp (item_types[i].name_pl, name)) |
377 | { |
378 | { |
378 | LOG (llevInfo, |
379 | LOG (llevInfo, |
379 | "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); |
380 | return &item_types[i]; |
381 | return &item_types[i]; |
381 | } |
382 | } |
|
|
383 | |
382 | return NULL; |
384 | return NULL; |
383 | } |
385 | } |
384 | |
386 | |
385 | /* describe_resistance generates the visible naming for resistances. |
387 | /* describe_resistance generates the visible naming for resistances. |
386 | * returns a static array of the description. This can return |
388 | * returns a static array of the description. This can return |
… | |
… | |
419 | */ |
421 | */ |
420 | const char * |
422 | const char * |
421 | query_weight (const object *op) |
423 | query_weight (const object *op) |
422 | { |
424 | { |
423 | static char buf[10]; |
425 | static char buf[10]; |
424 | sint32 i = (op->nrof ? op->nrof : 1) * op->weight + op->carrying; |
426 | sint32 i = op->total_weight (); |
425 | |
427 | |
426 | if (op->weight < 0) |
428 | if (op->weight < 0) |
427 | return " "; |
429 | return " "; |
428 | |
430 | |
429 | if (i % 1000) |
431 | if (i % 1000) |
… | |
… | |
538 | * contain any information about object status (worn/cursed/etc.) |
540 | * contain any information about object status (worn/cursed/etc.) |
539 | */ |
541 | */ |
540 | const char * |
542 | const char * |
541 | query_short_name (const object *op) |
543 | query_short_name (const object *op) |
542 | { |
544 | { |
543 | if (op->name == 0) |
545 | if (!op->name) |
544 | return "(null)"; |
546 | return "(null)"; |
545 | |
547 | |
546 | if (!op->nrof |
548 | if (!op->nrof |
547 | && !op->weight |
549 | && !op->weight |
548 | && !op->title |
550 | && !op->title |
… | |
… | |
571 | if (op->type != SPELLBOOK) |
573 | if (op->type != SPELLBOOK) |
572 | buf.printf (" (lvl %d)", op->level); |
574 | buf.printf (" (lvl %d)", op->level); |
573 | } |
575 | } |
574 | break; |
576 | break; |
575 | |
577 | |
576 | case ALTAR: |
578 | case ALTAR: |
577 | case TRIGGER_ALTAR: |
579 | case TRIGGER_ALTAR: |
578 | case IDENTIFY_ALTAR: |
580 | case IDENTIFY_ALTAR: |
|
|
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", 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 | { |
… | |
… | |
1193 | } |
1237 | } |
1194 | |
1238 | |
1195 | void |
1239 | void |
1196 | examine (object *op, object *tmp) |
1240 | examine (object *op, object *tmp) |
1197 | { |
1241 | { |
1198 | std::string s = tmp->describe (op); |
1242 | std::string info = tmp->describe (op); |
1199 | |
1243 | op->contr->infobox (MSG_CHANNEL ("examine"), info.c_str ()); |
1200 | new_draw_info (NDI_UNIQUE, 0, op, s.c_str ()); |
|
|
1201 | } |
1244 | } |
1202 | |
1245 | |
1203 | /* |
1246 | /* |
1204 | * inventory prints object's inventory. If inv==NULL then print player's |
1247 | * inventory prints object's inventory. If inv==NULL then print player's |
1205 | * inventory. |
1248 | * inventory. |
… | |
… | |
1210 | { |
1253 | { |
1211 | static dynbuf_text buf; buf.clear (); |
1254 | static dynbuf_text buf; buf.clear (); |
1212 | |
1255 | |
1213 | for (object *tmp = inv; tmp; tmp = tmp->below) |
1256 | for (object *tmp = inv; tmp; tmp = tmp->below) |
1214 | if (who && QUERY_FLAG (who, FLAG_WIZ)) |
1257 | if (who && QUERY_FLAG (who, FLAG_WIZ)) |
1215 | 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 ()); |
1216 | else if (!tmp->invisible && (type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED))) |
1259 | else if (!tmp->invisible && (type == CONTAINER || QUERY_FLAG (tmp, FLAG_APPLIED))) |
1217 | 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 ()); |
1218 | |
1261 | |
1219 | if (buf.size ()) |
1262 | if (buf.size ()) |
1220 | buf.printf ("%s(total weight: %s)\n", indent, query_weight (this)); |
1263 | buf.printf ("%s(total weight: %s)\n", indent, query_weight ()); |
1221 | else |
1264 | else |
1222 | buf.printf ("%s(empty)\n", indent); |
1265 | buf.printf ("%s(empty)\n", indent); |
1223 | |
1266 | |
1224 | return buf; |
1267 | return buf; |
1225 | } |
1268 | } |
… | |
… | |
1357 | * Supposed to fix face-values as well here, but later. |
1400 | * Supposed to fix face-values as well here, but later. |
1358 | */ |
1401 | */ |
1359 | void |
1402 | void |
1360 | identify (object *op) |
1403 | identify (object *op) |
1361 | { |
1404 | { |
1362 | object *pl; |
|
|
1363 | |
|
|
1364 | SET_FLAG (op, FLAG_IDENTIFIED); |
1405 | SET_FLAG (op, FLAG_IDENTIFIED); |
1365 | CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); |
1406 | CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); |
1366 | CLEAR_FLAG (op, FLAG_NO_SKILL_IDENT); |
1407 | CLEAR_FLAG (op, FLAG_NO_SKILL_IDENT); |
1367 | |
1408 | |
1368 | /* |
1409 | /* |
… | |
… | |
1375 | { |
1416 | { |
1376 | if (op->inv && op->randomitems) |
1417 | if (op->inv && op->randomitems) |
1377 | op->title = op->inv->name; |
1418 | op->title = op->inv->name; |
1378 | else if (op->arch) |
1419 | else if (op->arch) |
1379 | { |
1420 | { |
1380 | op->name = op->arch->object::name; |
1421 | op->name = op->arch->object::name; |
1381 | op->name_pl = op->arch->object::name_pl; |
1422 | op->name_pl = op->arch->object::name_pl; |
1382 | } |
1423 | } |
1383 | } |
1424 | } |
1384 | |
1425 | |
1385 | /* 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 */ |
1386 | if (op->map) |
1427 | if (op->map) |
1387 | update_object (op, UP_OBJ_CHANGE); |
1428 | update_object (op, UP_OBJ_CHANGE); |
1388 | else |
1429 | |
1389 | { |
1430 | if (object *pl = op->visible_to ()) |
1390 | pl = op->in_player (); |
|
|
1391 | if (pl) |
|
|
1392 | /* 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 |
1393 | * it all. |
1432 | * it all. |
1394 | */ |
1433 | */ |
1395 | esrv_send_item (pl, op); |
1434 | esrv_send_item (pl, op); |
1396 | } |
|
|
1397 | } |
1435 | } |
1398 | |
1436 | |