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 it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
… | |
… | |
52 | > tl_map_t; |
52 | > tl_map_t; |
53 | |
53 | |
54 | static tl_map_t tl_map; |
54 | static tl_map_t tl_map; |
55 | |
55 | |
56 | //TODO: class method |
56 | //TODO: class method |
|
|
57 | static void free_treasurestruct (treasure *t); // bleh desu |
57 | static void |
58 | static void |
58 | clear (treasurelist *tl) |
59 | clear (treasurelist *tl) |
59 | { |
60 | { |
60 | void free_treasurestruct (treasure *t); |
|
|
61 | |
|
|
62 | if (tl->items) |
61 | if (tl->items) |
63 | { |
62 | { |
64 | free_treasurestruct (tl->items); |
63 | free_treasurestruct (tl->items); |
65 | tl->items = 0; |
64 | tl->items = 0; |
66 | } |
65 | } |
… | |
… | |
497 | * This code presumes that op has had its spell object created (in op->inv) |
496 | * This code presumes that op has had its spell object created (in op->inv) |
498 | * |
497 | * |
499 | * elmex Wed Aug 9 17:44:59 CEST 2006: |
498 | * elmex Wed Aug 9 17:44:59 CEST 2006: |
500 | * Removed multiplicator, too many high-level items were generated on low-difficulty maps. |
499 | * Removed multiplicator, too many high-level items were generated on low-difficulty maps. |
501 | */ |
500 | */ |
502 | int |
501 | static int |
503 | level_for_item (const object *op, int difficulty) |
502 | level_for_item (const object *op, int difficulty) |
504 | { |
503 | { |
505 | if (!op->inv) |
504 | if (!op->inv) |
506 | { |
505 | { |
507 | LOG (llevError, "level_for_item: Object %s has no inventory!\n", &op->name); |
506 | LOG (llevError, "level_for_item: Object %s has no inventory!\n", &op->name); |
… | |
… | |
524 | * elmex Thu Aug 10 18:45:44 CEST 2006: |
523 | * elmex Thu Aug 10 18:45:44 CEST 2006: |
525 | * Scaling difficulty by max_level, as difficulty is a level and not some |
524 | * Scaling difficulty by max_level, as difficulty is a level and not some |
526 | * weird integer between 1-31. |
525 | * weird integer between 1-31. |
527 | * |
526 | * |
528 | */ |
527 | */ |
529 | int |
528 | static int |
530 | magic_from_difficulty (int difficulty) |
529 | magic_from_difficulty (int difficulty) |
531 | { |
530 | { |
532 | int percent = 0, magic = 0; |
531 | int percent = 0, magic = 0; |
533 | int scaled_diff = (int) (((double) difficulty / settings.max_level) * DIFFLEVELS); |
532 | int scaled_diff = (int) (((double) difficulty / settings.max_level) * DIFFLEVELS); |
534 | |
533 | |
… | |
… | |
624 | * 1) Since rings can have multiple bonuses, if the same bonus |
623 | * 1) Since rings can have multiple bonuses, if the same bonus |
625 | * is rolled again, increase it - the bonuses now stack with |
624 | * is rolled again, increase it - the bonuses now stack with |
626 | * other bonuses previously rolled and ones the item might natively have. |
625 | * other bonuses previously rolled and ones the item might natively have. |
627 | * 2) Add code to deal with new PR method. |
626 | * 2) Add code to deal with new PR method. |
628 | */ |
627 | */ |
629 | void |
628 | static void |
630 | set_ring_bonus (object *op, int bonus) |
629 | set_ring_bonus (object *op, int bonus) |
631 | { |
630 | { |
632 | |
|
|
633 | int r = rndm (bonus > 0 ? 25 : 11); |
631 | int r = rndm (bonus > 0 ? 25 : 11); |
634 | |
632 | |
635 | if (op->type == AMULET) |
633 | if (op->type == AMULET) |
636 | { |
634 | { |
637 | if (!(rndm (21))) |
635 | if (!(rndm (21))) |
… | |
… | |
760 | * higher is the chance of returning a low number. |
758 | * higher is the chance of returning a low number. |
761 | * It is only used in fix_generated_treasure() to set bonuses on |
759 | * It is only used in fix_generated_treasure() to set bonuses on |
762 | * rings and amulets. |
760 | * rings and amulets. |
763 | * Another scheme is used to calculate the magic of weapons and armours. |
761 | * Another scheme is used to calculate the magic of weapons and armours. |
764 | */ |
762 | */ |
765 | int |
763 | static int |
766 | get_magic (int diff) |
764 | get_magic (int diff) |
767 | { |
765 | { |
768 | int i; |
766 | int i; |
769 | |
767 | |
770 | if (diff < 3) |
768 | if (diff < 3) |
… | |
… | |
776 | |
774 | |
777 | return 4; |
775 | return 4; |
778 | } |
776 | } |
779 | |
777 | |
780 | /* special_potion() - so that old potion code is still done right. */ |
778 | /* special_potion() - so that old potion code is still done right. */ |
781 | int |
779 | static int |
782 | special_potion (object *op) |
780 | special_potion (object *op) |
783 | { |
781 | { |
784 | if (op->attacktype) |
782 | if (op->attacktype) |
785 | return 1; |
783 | return 1; |
786 | |
784 | |
… | |
… | |
836 | create_treasure (op->randomitems, op, flags & ~GT_ENVIRONMENT, difficulty, 0); |
834 | create_treasure (op->randomitems, op, flags & ~GT_ENVIRONMENT, difficulty, 0); |
837 | /* So the treasure doesn't get created again */ |
835 | /* So the treasure doesn't get created again */ |
838 | op->randomitems = 0; |
836 | op->randomitems = 0; |
839 | } |
837 | } |
840 | |
838 | |
841 | if (difficulty < 1) |
839 | max_it (difficulty, 1); |
842 | difficulty = 1; |
|
|
843 | |
840 | |
844 | if (INVOKE_OBJECT (ADD_BONUS, op, |
841 | if (INVOKE_OBJECT (ADD_BONUS, op, |
845 | ARG_OBJECT (creator != op ? creator : 0), |
842 | ARG_OBJECT (creator != op ? creator : 0), |
846 | ARG_INT (difficulty), ARG_INT (max_magic), |
843 | ARG_INT (difficulty), ARG_INT (max_magic), |
847 | ARG_INT (flags))) |
844 | ARG_INT (flags))) |
… | |
… | |
906 | * again below */ |
903 | * again below */ |
907 | } |
904 | } |
908 | } |
905 | } |
909 | |
906 | |
910 | /* materialtype modifications. Note we allow this on artifacts. */ |
907 | /* materialtype modifications. Note we allow this on artifacts. */ |
911 | set_materialname (op, difficulty, NULL); |
908 | select_material (op, difficulty); |
912 | |
909 | |
913 | if (flags & GT_MINIMAL) |
910 | if (flags & GT_MINIMAL) |
914 | { |
911 | { |
915 | if (op->type == POTION) |
912 | if (op->type == POTION) |
916 | /* Handle healing and magic power potions */ |
913 | /* Handle healing and magic power potions */ |
… | |
… | |
947 | int too_many_tries = 0, is_special = 0; |
944 | int too_many_tries = 0, is_special = 0; |
948 | |
945 | |
949 | /* Handle healing and magic power potions */ |
946 | /* Handle healing and magic power potions */ |
950 | if (op->stats.sp && !op->randomitems) |
947 | if (op->stats.sp && !op->randomitems) |
951 | { |
948 | { |
952 | object *tmp; |
|
|
953 | |
|
|
954 | tmp = get_archetype (spell_mapping[op->stats.sp]); |
949 | object *tmp = get_archetype (spell_mapping[op->stats.sp]); |
955 | insert_ob_in_ob (tmp, op); |
950 | insert_ob_in_ob (tmp, op); |
956 | op->stats.sp = 0; |
951 | op->stats.sp = 0; |
957 | } |
952 | } |
958 | |
953 | |
959 | while (!(is_special = special_potion (op)) && !op->inv) |
954 | while (!(is_special = special_potion (op)) && !op->inv) |
… | |
… | |
967 | * since the value set on those is already correct. |
962 | * since the value set on those is already correct. |
968 | */ |
963 | */ |
969 | if (op->inv && op->randomitems) |
964 | if (op->inv && op->randomitems) |
970 | { |
965 | { |
971 | /* value multiplier is same as for scrolls */ |
966 | /* value multiplier is same as for scrolls */ |
972 | op->value = (op->value * op->inv->value); |
967 | op->value *= op->inv->value; |
973 | op->level = op->inv->level / 2 + rndm (difficulty) + rndm (difficulty); |
968 | op->level = op->inv->level / 2 + rndm (difficulty) + rndm (difficulty); |
974 | } |
969 | } |
975 | else |
970 | else |
976 | { |
971 | { |
977 | op->name = "potion"; |
972 | op->name = "potion"; |
978 | op->name_pl = "potions"; |
973 | op->name_pl = "potions"; |
979 | } |
974 | } |
980 | |
975 | |
981 | if (!(flags & GT_ONLY_GOOD) && rndm (2)) |
976 | if (!(flags & GT_ONLY_GOOD) && rndm (2)) |
982 | SET_FLAG (op, FLAG_CURSED); |
977 | SET_FLAG (op, FLAG_CURSED); |
|
|
978 | |
983 | break; |
979 | break; |
984 | } |
980 | } |
985 | |
981 | |
986 | case AMULET: |
982 | case AMULET: |
987 | if (IS_ARCH (op->arch, amulet)) |
983 | if (IS_ARCH (op->arch, amulet)) |
… | |
… | |
1099 | * 10 time multiplier). This way, the value are a bit more reasonable. |
1095 | * 10 time multiplier). This way, the value are a bit more reasonable. |
1100 | */ |
1096 | */ |
1101 | op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); |
1097 | op->value = op->value * op->inv->value * (op->level + 50) / (op->inv->level + 50); |
1102 | /* maxhp is used to denote how many 'charges' the rod holds before */ |
1098 | /* maxhp is used to denote how many 'charges' the rod holds before */ |
1103 | if (op->stats.maxhp) |
1099 | if (op->stats.maxhp) |
1104 | op->stats.maxhp *= MAX (op->inv->stats.sp, op->inv->stats.grace); |
1100 | op->stats.maxhp *= max (op->inv->stats.sp, op->inv->stats.grace); |
1105 | else |
1101 | else |
1106 | op->stats.maxhp = 2 * MAX (op->inv->stats.sp, op->inv->stats.grace); |
1102 | op->stats.maxhp = 2 * max (op->inv->stats.sp, op->inv->stats.grace); |
1107 | |
1103 | |
1108 | op->stats.hp = op->stats.maxhp; |
1104 | op->stats.hp = op->stats.maxhp; |
1109 | break; |
1105 | break; |
1110 | |
1106 | |
1111 | case SCROLL: |
1107 | case SCROLL: |
… | |
… | |
1210 | |
1206 | |
1211 | { |
1207 | { |
1212 | if (!strcmp (f.get_str (), "all")) |
1208 | if (!strcmp (f.get_str (), "all")) |
1213 | break; |
1209 | break; |
1214 | |
1210 | |
1215 | char *next, *cp = f.get_str (); |
1211 | const char *cp = f.get_str (); |
1216 | |
1212 | char *next; |
1217 | do |
1213 | do |
1218 | { |
1214 | { |
1219 | if ((next = strchr (cp, ','))) |
1215 | if ((next = strchr (cp, ','))) |
1220 | *next++ = '\0'; |
1216 | *next++ = '\0'; |
1221 | |
1217 | |
… | |
… | |
1467 | op->value *= change->value; |
1463 | op->value *= change->value; |
1468 | |
1464 | |
1469 | if (change->materials) |
1465 | if (change->materials) |
1470 | op->materials = change->materials; |
1466 | op->materials = change->materials; |
1471 | |
1467 | |
1472 | if (change->materialname) |
1468 | if (change->material != MATERIAL_NULL) |
1473 | op->materialname = change->materialname; |
1469 | op->material = change->material; |
1474 | |
1470 | |
1475 | if (change->slaying) |
1471 | if (change->slaying) |
1476 | op->slaying = change->slaying; |
1472 | op->slaying = change->slaying; |
1477 | |
1473 | |
1478 | if (change->race) |
1474 | if (change->race) |
… | |
… | |
1660 | |
1656 | |
1661 | SET_FLAG (item, FLAG_NO_STEAL); |
1657 | SET_FLAG (item, FLAG_NO_STEAL); |
1662 | } |
1658 | } |
1663 | } |
1659 | } |
1664 | |
1660 | |
1665 | void |
1661 | static void |
1666 | free_treasurestruct (treasure *t) |
1662 | free_treasurestruct (treasure *t) |
1667 | { |
1663 | { |
1668 | if (t->next) free_treasurestruct (t->next); |
1664 | if (t->next) free_treasurestruct (t->next); |
1669 | if (t->next_yes) free_treasurestruct (t->next_yes); |
1665 | if (t->next_yes) free_treasurestruct (t->next_yes); |
1670 | if (t->next_no) free_treasurestruct (t->next_no); |
1666 | if (t->next_no) free_treasurestruct (t->next_no); |
1671 | |
1667 | |
1672 | delete t; |
1668 | delete t; |
1673 | } |
1669 | } |
1674 | |
1670 | |
1675 | void |
1671 | static void |
1676 | free_charlinks (linked_char *lc) |
1672 | free_charlinks (linked_char *lc) |
1677 | { |
1673 | { |
1678 | if (lc->next) |
1674 | if (lc->next) |
1679 | free_charlinks (lc->next); |
1675 | free_charlinks (lc->next); |
1680 | |
1676 | |
1681 | delete lc; |
1677 | delete lc; |
1682 | } |
1678 | } |
1683 | |
1679 | |
1684 | void |
1680 | static void |
1685 | free_artifact (artifact *at) |
1681 | free_artifact (artifact *at) |
1686 | { |
1682 | { |
1687 | if (at->next) free_artifact (at->next); |
1683 | if (at->next) free_artifact (at->next); |
1688 | if (at->allowed) free_charlinks (at->allowed); |
1684 | if (at->allowed) free_charlinks (at->allowed); |
1689 | |
1685 | |
1690 | at->item->destroy (); |
1686 | at->item->destroy (); |
1691 | |
1687 | |
1692 | sfree (at); |
1688 | sfree (at); |
1693 | } |
1689 | } |
1694 | |
1690 | |
1695 | void |
|
|
1696 | free_artifactlist (artifactlist *al) |
|
|
1697 | { |
|
|
1698 | artifactlist *nextal; |
|
|
1699 | |
|
|
1700 | for (al = first_artifactlist; al; al = nextal) |
|
|
1701 | { |
|
|
1702 | nextal = al->next; |
|
|
1703 | |
|
|
1704 | if (al->items) |
|
|
1705 | free_artifact (al->items); |
|
|
1706 | |
|
|
1707 | sfree (al); |
|
|
1708 | } |
|
|
1709 | } |
|
|
1710 | |
|
|
1711 | void |
|
|
1712 | free_all_treasures (void) |
|
|
1713 | { |
|
|
1714 | treasurelist *tl, *next; |
|
|
1715 | |
|
|
1716 | for (tl = first_treasurelist; tl; tl = next) |
|
|
1717 | { |
|
|
1718 | clear (tl); |
|
|
1719 | |
|
|
1720 | next = tl->next; |
|
|
1721 | delete tl; |
|
|
1722 | } |
|
|
1723 | |
|
|
1724 | free_artifactlist (first_artifactlist); |
|
|
1725 | } |
|
|