… | |
… | |
1529 | insert_ob_in_ob (force, tmp); |
1529 | insert_ob_in_ob (force, tmp); |
1530 | tmp->update_stats (); |
1530 | tmp->update_stats (); |
1531 | return 1; |
1531 | return 1; |
1532 | } |
1532 | } |
1533 | |
1533 | |
1534 | |
|
|
1535 | |
|
|
1536 | /* Alchemy code by Mark Wedel |
1534 | /* Alchemy code by Mark Wedel |
1537 | * |
1535 | * |
1538 | * This code adds a new spell, called alchemy. Alchemy will turn |
1536 | * This code adds a new spell, called alchemy. Alchemy will turn |
1539 | * objects to gold nuggets, the value of the gold nuggets being |
1537 | * objects to gold nuggets, the value of the gold nuggets being |
1540 | * about 90% of that of the item itself. It uses the value of the |
1538 | * about 90% of that of the item itself. It uses the value of the |
… | |
… | |
1551 | * |
1549 | * |
1552 | * There is also a chance (1:30) that you will get nothing at all |
1550 | * There is also a chance (1:30) that you will get nothing at all |
1553 | * for the object. There is also a maximum weight that will be |
1551 | * for the object. There is also a maximum weight that will be |
1554 | * alchemised. |
1552 | * alchemised. |
1555 | */ |
1553 | */ |
1556 | |
|
|
1557 | /* I didn't feel like passing these as argumeents to the |
|
|
1558 | * two functions that need them. Real values are put in them |
|
|
1559 | * when the spell is cast, and these are freed when the spell |
|
|
1560 | * is finished. |
|
|
1561 | */ |
|
|
1562 | static object *small, *large; |
|
|
1563 | |
|
|
1564 | static void |
1554 | static void |
1565 | alchemy_object (object *obj, int *small_nuggets, int *large_nuggets, int *weight) |
1555 | alchemy_object (object *obj, uint64 &total_value, int &total_weight) |
1566 | { |
1556 | { |
1567 | uint64 value = query_cost (obj, NULL, F_TRUE); |
1557 | uint64 value = query_cost (obj, NULL, F_TRUE); |
1568 | |
1558 | |
1569 | /* Give third price when we alchemy money (This should hopefully |
1559 | /* Give third price when we alchemy money (This should hopefully |
1570 | * make it so that it isn't worth it to alchemy money, sell |
1560 | * make it so that it isn't worth it to alchemy money, sell |
1571 | * the nuggets, alchemy the gold from that, etc. |
1561 | * the nuggets, alchemy the gold from that, etc. |
1572 | * Otherwise, give 9 silver on the gold for other objects, |
1562 | * Otherwise, give 9 silver on the gold for other objects, |
1573 | * so that it would still be more affordable to haul |
1563 | * so that it would still be more affordable to haul |
1574 | * the stuff back to town. |
1564 | * the stuff back to town. |
1575 | */ |
1565 | */ |
1576 | |
|
|
1577 | if (QUERY_FLAG (obj, FLAG_UNPAID)) |
1566 | if (QUERY_FLAG (obj, FLAG_UNPAID)) |
1578 | value = 0; |
1567 | value = 0; |
1579 | else if (obj->type == MONEY || obj->type == GEM) |
1568 | else if (obj->type == MONEY || obj->type == GEM) |
1580 | value /= 3; |
1569 | value /= 3; |
1581 | else |
1570 | else |
1582 | value = (value * 9) / 10; |
1571 | value = (value * 9) / 10; |
1583 | |
1572 | |
1584 | value /= 4; // fix by GHJ, don't understand, pcg |
1573 | value /= 4; // fix by GHJ, don't understand, pcg |
1585 | |
1574 | |
1586 | if (obj->value > 0 && rndm (0, 29)) |
1575 | if (obj->value > 0 && rndm (0, 29)) |
1587 | { |
1576 | total_value += value; |
1588 | int count; |
|
|
1589 | |
1577 | |
1590 | count = value / large->value; |
|
|
1591 | *large_nuggets += count; |
|
|
1592 | value -= (uint64) count *(uint64) large->value; |
|
|
1593 | |
|
|
1594 | count = value / small->value; |
|
|
1595 | *small_nuggets += count; |
|
|
1596 | } |
|
|
1597 | |
|
|
1598 | /* Turn 25 small nuggets into 1 large nugget. If the value |
|
|
1599 | * of large nuggets is not evenly divisable by the small nugget |
|
|
1600 | * value, take off an extra small_nugget (Assuming small_nuggets!=0) |
|
|
1601 | */ |
|
|
1602 | if (*small_nuggets * small->value >= large->value) |
|
|
1603 | { |
|
|
1604 | (*large_nuggets)++; |
|
|
1605 | *small_nuggets -= large->value / small->value; |
|
|
1606 | if (*small_nuggets && large->value % small->value) |
|
|
1607 | (*small_nuggets)--; |
|
|
1608 | } |
|
|
1609 | |
|
|
1610 | weight += obj->weight; |
1578 | total_weight += obj->total_weight (); |
|
|
1579 | |
1611 | obj->destroy (); |
1580 | obj->destroy (); |
1612 | } |
1581 | } |
1613 | |
1582 | |
1614 | static void |
1583 | static void |
1615 | update_map (object *op, maptile *m, int small_nuggets, int large_nuggets, int x, int y) |
1584 | update_map (object *op, maptile *m, int small_nuggets, object *small, int large_nuggets, object *large, int x, int y) |
1616 | { |
1585 | { |
1617 | object *tmp; |
|
|
1618 | int flag = 0; |
1586 | int flag = 0; |
1619 | |
1587 | |
1620 | /* Put any nuggets below the player, but we can only pass this |
1588 | /* Put any nuggets below the player, but we can only pass this |
1621 | * flag if we are on the same space as the player |
1589 | * flag if we are on the same space as the player |
1622 | */ |
1590 | */ |
1623 | if (x == op->x && y == op->y && op->map == m) |
1591 | if (x == op->x && y == op->y && op->map == m) |
1624 | flag = INS_BELOW_ORIGINATOR; |
1592 | flag = INS_BELOW_ORIGINATOR; |
1625 | |
1593 | |
1626 | if (small_nuggets) |
1594 | if (small_nuggets) |
1627 | { |
1595 | { |
1628 | tmp = small->clone (); |
1596 | object *tmp = small->clone (); |
1629 | tmp->nrof = small_nuggets; |
1597 | tmp->nrof = small_nuggets; |
1630 | m->insert (tmp, x, y, op, flag); |
1598 | m->insert (tmp, x, y, op, flag); |
1631 | } |
1599 | } |
1632 | |
1600 | |
1633 | if (large_nuggets) |
1601 | if (large_nuggets) |
1634 | { |
1602 | { |
1635 | tmp = large->clone (); |
1603 | object *tmp = large->clone (); |
1636 | tmp->nrof = large_nuggets; |
1604 | tmp->nrof = large_nuggets; |
1637 | m->insert (tmp, x, y, op, flag); |
1605 | m->insert (tmp, x, y, op, flag); |
1638 | } |
1606 | } |
|
|
1607 | |
|
|
1608 | if (object *pl = m->at (x, y).player ()) |
|
|
1609 | if (pl->contr->ns) |
|
|
1610 | pl->contr->ns->look_position = 0; |
1639 | } |
1611 | } |
1640 | |
1612 | |
1641 | int |
1613 | int |
1642 | alchemy (object *op, object *caster, object *spell_ob) |
1614 | alchemy (object *op, object *caster, object *spell_ob) |
1643 | { |
1615 | { |
1644 | int x, y, weight = 0, weight_max, large_nuggets, small_nuggets, mflags; |
1616 | int weight = 0, mflags; |
1645 | sint16 nx, ny; |
|
|
1646 | object *next, *tmp; |
|
|
1647 | maptile *mp; |
1617 | maptile *mp; |
1648 | |
1618 | |
1649 | if (op->type != PLAYER) |
1619 | if (op->type != PLAYER) |
1650 | return 0; |
1620 | return 0; |
1651 | |
1621 | |
1652 | /* Put a maximum weight of items that can be alchemied. Limits the power |
1622 | /* Put a maximum weight of items that can be alchemised. Limits the power |
1653 | * some, and also prevents people from alcheming every table/chair/clock |
1623 | * some, and also prevents people from alchemising every table/chair/clock |
1654 | * in sight |
1624 | * in sight |
1655 | */ |
1625 | */ |
1656 | weight_max = spell_ob->duration + +SP_level_duration_adjust (caster, spell_ob); |
1626 | int duration = spell_ob->duration + SP_level_duration_adjust (caster, spell_ob); |
1657 | weight_max *= 1000; |
1627 | int weight_max = duration * 1000; |
1658 | small = get_archetype ("smallnugget"), large = get_archetype ("largenugget"); |
1628 | uint64 value_max = duration * 1000; |
1659 | |
1629 | |
|
|
1630 | object *large = get_archetype ("largenugget"); |
|
|
1631 | object *small = get_archetype ("smallnugget"); |
|
|
1632 | |
1660 | for (y = op->y - 1; y <= op->y + 1; y++) |
1633 | for (int y = op->y - 1; y <= op->y + 1; y++) |
1661 | { |
1634 | { |
1662 | for (x = op->x - 1; x <= op->x + 1; x++) |
1635 | for (int x = op->x - 1; x <= op->x + 1; x++) |
1663 | { |
1636 | { |
|
|
1637 | uint64 value = 0; |
|
|
1638 | |
1664 | nx = x; |
1639 | sint16 nx = x; |
1665 | ny = y; |
1640 | sint16 ny = y; |
1666 | |
1641 | |
1667 | mp = op->map; |
1642 | mp = op->map; |
1668 | |
1643 | |
1669 | mflags = get_map_flags (mp, &mp, nx, ny, &nx, &ny); |
1644 | mflags = get_map_flags (mp, &mp, nx, ny, &nx, &ny); |
1670 | |
1645 | |
… | |
… | |
1676 | * ground level effect. |
1651 | * ground level effect. |
1677 | */ |
1652 | */ |
1678 | if (GET_MAP_MOVE_BLOCK (mp, nx, ny) & MOVE_WALK) |
1653 | if (GET_MAP_MOVE_BLOCK (mp, nx, ny) & MOVE_WALK) |
1679 | continue; |
1654 | continue; |
1680 | |
1655 | |
1681 | small_nuggets = 0; |
|
|
1682 | large_nuggets = 0; |
|
|
1683 | |
|
|
1684 | for (tmp = mp->at (nx, ny).bot; tmp; tmp = next) |
1656 | for (object *next, *tmp = mp->at (nx, ny).bot; tmp; tmp = next) |
1685 | { |
1657 | { |
1686 | next = tmp->above; |
1658 | next = tmp->above; |
1687 | |
1659 | |
1688 | if (tmp->weight > 0 && !QUERY_FLAG (tmp, FLAG_NO_PICK) && |
1660 | if (tmp->weight > 0 && !QUERY_FLAG (tmp, FLAG_NO_PICK) && |
1689 | !QUERY_FLAG (tmp, FLAG_ALIVE) && !QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) |
1661 | !QUERY_FLAG (tmp, FLAG_ALIVE) && !QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) |
… | |
… | |
1695 | for (tmp1 = tmp->inv; tmp1; tmp1 = next1) |
1667 | for (tmp1 = tmp->inv; tmp1; tmp1 = next1) |
1696 | { |
1668 | { |
1697 | next1 = tmp1->below; |
1669 | next1 = tmp1->below; |
1698 | if (tmp1->weight > 0 && !QUERY_FLAG (tmp1, FLAG_NO_PICK) && |
1670 | if (tmp1->weight > 0 && !QUERY_FLAG (tmp1, FLAG_NO_PICK) && |
1699 | !QUERY_FLAG (tmp1, FLAG_ALIVE) && !QUERY_FLAG (tmp1, FLAG_IS_CAULDRON)) |
1671 | !QUERY_FLAG (tmp1, FLAG_ALIVE) && !QUERY_FLAG (tmp1, FLAG_IS_CAULDRON)) |
1700 | alchemy_object (tmp1, &small_nuggets, &large_nuggets, &weight); |
1672 | alchemy_object (tmp1, value, weight); |
1701 | } |
1673 | } |
1702 | } |
1674 | } |
1703 | |
1675 | |
1704 | alchemy_object (tmp, &small_nuggets, &large_nuggets, &weight); |
1676 | alchemy_object (tmp, value, weight); |
1705 | |
1677 | |
1706 | if (weight > weight_max) |
1678 | if (weight > weight_max) |
1707 | { |
1679 | break; |
1708 | update_map (op, mp, small_nuggets, large_nuggets, nx, ny); |
|
|
1709 | large->destroy (); |
|
|
1710 | small->destroy (); |
|
|
1711 | return 1; |
|
|
1712 | } |
1680 | } |
1713 | } /* is alchemable object */ |
1681 | } |
1714 | } /* process all objects on this space */ |
1682 | |
|
|
1683 | value = min (value, value_max); |
|
|
1684 | |
|
|
1685 | uint64 count = value / large->value; |
|
|
1686 | int large_nuggets = count; |
|
|
1687 | value -= count * large->value; |
|
|
1688 | |
|
|
1689 | count = value / small->value; |
|
|
1690 | int small_nuggets = count; |
1715 | |
1691 | |
1716 | /* Insert all the nuggets at one time. This probably saves time, but |
1692 | /* Insert all the nuggets at one time. This probably saves time, but |
1717 | * it also prevents us from alcheming nuggets that were just created |
1693 | * it also prevents us from alcheming nuggets that were just created |
1718 | * with this spell. |
1694 | * with this spell. |
1719 | */ |
1695 | */ |
1720 | update_map (op, mp, small_nuggets, large_nuggets, nx, ny); |
1696 | update_map (op, mp, small_nuggets, small, large_nuggets, large, nx, ny); |
1721 | } |
|
|
1722 | } |
|
|
1723 | |
1697 | |
|
|
1698 | if (weight > weight_max) |
|
|
1699 | goto bailout; |
|
|
1700 | } |
|
|
1701 | } |
|
|
1702 | |
|
|
1703 | bailout: |
1724 | large->destroy (); |
1704 | large->destroy (); |
1725 | small->destroy (); |
1705 | small->destroy (); |
1726 | /* reset this so that if player standing on a big pile of stuff, |
|
|
1727 | * it is redrawn properly. |
|
|
1728 | */ |
|
|
1729 | op->contr->ns->look_position = 0; |
|
|
1730 | return 1; |
1706 | return 1; |
1731 | } |
1707 | } |
1732 | |
1708 | |
1733 | |
1709 | |
1734 | /* This function removes the cursed/damned status on equipped |
1710 | /* This function removes the cursed/damned status on equipped |
… | |
… | |
1761 | } |
1737 | } |
1762 | |
1738 | |
1763 | if (op->type == PLAYER) |
1739 | if (op->type == PLAYER) |
1764 | { |
1740 | { |
1765 | if (success) |
1741 | if (success) |
1766 | { |
|
|
1767 | new_draw_info (NDI_UNIQUE, 0, op, "You feel like some of your items are looser now."); |
1742 | new_draw_info (NDI_UNIQUE, 0, op, "You feel like some of your items are looser now."); |
1768 | } |
|
|
1769 | else |
1743 | else |
1770 | { |
1744 | { |
1771 | if (was_one) |
1745 | if (was_one) |
1772 | new_draw_info (NDI_UNIQUE, 0, op, "You failed to remove the curse."); |
1746 | new_draw_info (NDI_UNIQUE, 0, op, "You failed to remove the curse."); |
1773 | else |
1747 | else |