ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/player.C
(Generate patch)

Comparing deliantra/server/server/player.C (file contents):
Revision 1.236 by root, Thu Nov 5 14:56:06 2009 UTC vs.
Revision 1.237 by root, Thu Nov 5 15:18:26 2009 UTC

1655 } 1655 }
1656 1656
1657 return true; 1657 return true;
1658} 1658}
1659 1659
1660/* find_key 1660static object *
1661 * We try to find a key for the door as passed. If we find a key
1662 * and successfully use it, we return the key, otherwise NULL
1663 * This function merges both normal and locked door, since the logic
1664 * for both is the same - just the specific key is different.
1665 * pl is the player,
1666 * inv is the objects inventory to searched
1667 * door is the door we are trying to match against.
1668 * This function can be called recursively to search containers.
1669 */
1670object *
1671find_key (object *pl, object *container, object *door) 1661find_key_ (object *pl, object *container, object *door)
1672{ 1662{
1673 object *tmp, *key; 1663 object *tmp, *key;
1674 1664
1675 /* Should not happen, but sanity checking is never bad */ 1665 /* Should not happen, but sanity checking is never bad */
1676 if (!container->inv) 1666 if (!container->inv)
1697 if (!tmp) 1687 if (!tmp)
1698 { 1688 {
1699 for (tmp = container->inv; tmp; tmp = tmp->below) 1689 for (tmp = container->inv; tmp; tmp = tmp->below)
1700 /* No reason to search empty containers */ 1690 /* No reason to search empty containers */
1701 if (tmp->type == CONTAINER && tmp->inv) 1691 if (tmp->type == CONTAINER && tmp->inv)
1702 if ((key = find_key (pl, tmp, door))) 1692 if ((key = find_key_ (pl, tmp, door)))
1703 return key; 1693 return key;
1704 1694
1705 if (!tmp) 1695 if (!tmp)
1706 return 0; 1696 return 0;
1707 } 1697 }
1739 } 1729 }
1740 1730
1741 return tmp; 1731 return tmp;
1742} 1732}
1743 1733
1734/* find_key
1735 * We try to find a key for the door as passed. If we find a key
1736 * and successfully use it, we return the key, otherwise NULL
1737 * This function merges both normal and locked door, since the logic
1738 * for both is the same - just the specific key is different.
1739 * pl is the player,
1740 * inv is the objects inventory to searched
1741 * door is the door we are trying to match against.
1742 * This function can be called recursively to search containers.
1743 */
1744object *
1745find_key (object *pl, object *container, object *door)
1746{
1747 if (door->slaying && is_match_expr (door->slaying))
1748 {
1749 // for match expressions, we try to find the key by applying the match
1750 // to the op itself, which is supposed to find the "key", instead
1751 // of searching through containers ourselves.
1752
1753 return match_one (door->slaying, container, door, pl, pl);
1754 }
1755 else
1756 return find_key_ (pl, container, door);
1757}
1758
1744/* moved door processing out of move_player_attack. 1759/* moved door processing out of move_player_attack.
1745 * returns 1 if player has opened the door with a key 1760 * returns 1 if player has opened the door with a key
1746 * such that the caller should not do anything more, 1761 * such that the caller should not do anything more,
1747 * 0 otherwise 1762 * 0 otherwise
1748 */ 1763 */
1751{ 1766{
1752 /* If its a door, try to find a key. If we do destroy the door, 1767 /* If its a door, try to find a key. If we do destroy the door,
1753 * might as well return immediately as there is nothing more to do - 1768 * might as well return immediately as there is nothing more to do -
1754 * otherwise, we fall through to the rest of the code. 1769 * otherwise, we fall through to the rest of the code.
1755 */ 1770 */
1756 object *key;
1757
1758 if (door->slaying && is_match_expr (door->slaying))
1759 {
1760 // for match expressions, we try to find the key by applying the match
1761 // to the op itself, which is supposed to find the "key", instead
1762 // of searching through containers ourselves.
1763
1764 key = match_one (door->slaying, op, door, op, op);
1765 }
1766 else
1767 key = find_key (op, op, door); 1771 object *key = find_key (op, op, door);
1768 1772
1769 /* If we found a key, do some extra work */ 1773 /* If we found a key, do some extra work */
1770 if (key) 1774 if (key)
1771 { 1775 {
1772 object *container = key->env; 1776 object *container = key->env;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines