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) |
… | |
… | |
807 | */ |
810 | */ |
808 | if (op->has_active_speed ()) |
811 | if (op->has_active_speed ()) |
809 | switch ((int) ((FABS (op->speed)) * 15)) |
812 | switch ((int) ((FABS (op->speed)) * 15)) |
810 | { |
813 | { |
811 | case 0: |
814 | case 0: |
812 | buf << "(very slow movement"; |
815 | buf << "(very slow movement)"; |
813 | break; |
816 | break; |
814 | case 1: |
817 | case 1: |
815 | buf << "(slow movement)"; |
818 | buf << "(slow movement)"; |
816 | break; |
819 | break; |
817 | case 2: |
820 | case 2: |
… | |
… | |
1209 | { |
1212 | { |
1210 | static dynbuf_text buf; buf.clear (); |
1213 | static dynbuf_text buf; buf.clear (); |
1211 | |
1214 | |
1212 | for (object *tmp = inv; tmp; tmp = tmp->below) |
1215 | for (object *tmp = inv; tmp; tmp = tmp->below) |
1213 | if (who && QUERY_FLAG (who, FLAG_WIZ)) |
1216 | 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)); |
1217 | 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))) |
1218 | 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)); |
1219 | buf.printf ("%s- %-36.36s %-8s\n", indent, tmp->query_name (), tmp->query_weight ()); |
1217 | |
1220 | |
1218 | if (buf.size ()) |
1221 | if (buf.size ()) |
1219 | buf.printf ("%s(total weight: %s)\n", indent, query_weight (this)); |
1222 | buf.printf ("%s(total weight: %s)\n", indent, query_weight ()); |
1220 | else |
1223 | else |
1221 | buf.printf ("%s(empty)\n", indent); |
1224 | buf.printf ("%s(empty)\n", indent); |
1222 | |
1225 | |
1223 | return buf; |
1226 | return buf; |
1224 | } |
1227 | } |
… | |
… | |
1356 | * Supposed to fix face-values as well here, but later. |
1359 | * Supposed to fix face-values as well here, but later. |
1357 | */ |
1360 | */ |
1358 | void |
1361 | void |
1359 | identify (object *op) |
1362 | identify (object *op) |
1360 | { |
1363 | { |
1361 | object *pl; |
|
|
1362 | |
|
|
1363 | SET_FLAG (op, FLAG_IDENTIFIED); |
1364 | SET_FLAG (op, FLAG_IDENTIFIED); |
1364 | CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); |
1365 | CLEAR_FLAG (op, FLAG_KNOWN_MAGICAL); |
1365 | CLEAR_FLAG (op, FLAG_NO_SKILL_IDENT); |
1366 | CLEAR_FLAG (op, FLAG_NO_SKILL_IDENT); |
1366 | |
1367 | |
1367 | /* |
1368 | /* |
… | |
… | |
1374 | { |
1375 | { |
1375 | if (op->inv && op->randomitems) |
1376 | if (op->inv && op->randomitems) |
1376 | op->title = op->inv->name; |
1377 | op->title = op->inv->name; |
1377 | else if (op->arch) |
1378 | else if (op->arch) |
1378 | { |
1379 | { |
1379 | op->name = op->arch->object::name; |
1380 | op->name = op->arch->object::name; |
1380 | op->name_pl = op->arch->object::name_pl; |
1381 | op->name_pl = op->arch->object::name_pl; |
1381 | } |
1382 | } |
1382 | } |
1383 | } |
1383 | |
1384 | |
1384 | /* If the object is on a map, make sure we update its face */ |
1385 | /* If the object is on a map, make sure we update its face */ |
1385 | if (op->map) |
1386 | if (op->map) |
1386 | update_object (op, UP_OBJ_CHANGE); |
1387 | update_object (op, UP_OBJ_CHANGE); |
1387 | else |
1388 | |
1388 | { |
1389 | if (object *pl = op->visible_to ()) |
1389 | pl = op->in_player (); |
|
|
1390 | if (pl) |
|
|
1391 | /* A lot of the values can change from an update - might as well send |
1390 | /* A lot of the values can change from an update - might as well send |
1392 | * it all. |
1391 | * it all. |
1393 | */ |
1392 | */ |
1394 | esrv_send_item (pl, op); |
1393 | esrv_send_item (pl, op); |
1395 | } |
|
|
1396 | } |
1394 | } |
1397 | |
1395 | |