… | |
… | |
1698 | * flag is what to do if the player doesn't have the skill: |
1698 | * flag is what to do if the player doesn't have the skill: |
1699 | */ |
1699 | */ |
1700 | static void |
1700 | static void |
1701 | add_player_exp (object *op, sint64 exp, const char *skill_name, int flag) |
1701 | add_player_exp (object *op, sint64 exp, const char *skill_name, int flag) |
1702 | { |
1702 | { |
1703 | object *skill_obj = NULL; |
1703 | object *skill_obj; |
1704 | sint64 limit, exp_to_add; |
1704 | sint64 limit, exp_to_add; |
1705 | int i; |
1705 | int i; |
1706 | |
1706 | |
1707 | /* prevents some forms of abuse. */ |
1707 | /* prevents some forms of abuse. */ |
1708 | if (op->contr->braced) |
1708 | if (op->contr->braced) |
… | |
… | |
1711 | /* Try to find the matching skill. |
1711 | /* Try to find the matching skill. |
1712 | * We do a shortcut/time saving mechanism first - see if it matches |
1712 | * We do a shortcut/time saving mechanism first - see if it matches |
1713 | * chosen_skill. This means we don't need to search through |
1713 | * chosen_skill. This means we don't need to search through |
1714 | * the players inventory. |
1714 | * the players inventory. |
1715 | */ |
1715 | */ |
|
|
1716 | skill_obj = 0; |
|
|
1717 | |
1716 | if (skill_name) |
1718 | if (skill_name) |
1717 | { |
1719 | { |
1718 | if (op->chosen_skill && op->chosen_skill->type == SKILL && !strcmp (skill_name, op->chosen_skill->skill)) |
1720 | skill_obj = op->contr->find_skill (skill_name); |
1719 | skill_obj = op->chosen_skill; |
|
|
1720 | else |
|
|
1721 | { |
|
|
1722 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
|
|
1723 | if (tmp->skill == skill_name && tmp->type == SKILL) |
|
|
1724 | { |
|
|
1725 | skill_obj = splay (tmp); |
|
|
1726 | break; |
|
|
1727 | } |
|
|
1728 | |
1721 | |
1729 | /* Player doesn't have the skill. Check to see what to do, and give |
1722 | /* Player doesn't have the skill. Check to see what to do, and give |
1730 | * it to the player if necessary |
1723 | * it to the player if necessary |
1731 | */ |
1724 | */ |
1732 | if (!skill_obj) |
1725 | if (!skill_obj) |
1733 | { |
1726 | { |
1734 | if (flag == SK_EXP_NONE) |
1727 | if (flag == SK_EXP_NONE) |
1735 | return; |
1728 | return; |
|
|
1729 | |
1736 | else if (flag == SK_EXP_ADD_SKILL) |
1730 | if (flag == SK_EXP_ADD_SKILL) |
1737 | skill_obj = give_skill_by_name (op, skill_name); |
1731 | skill_obj = give_skill_by_name (op, skill_name); |
1738 | } |
|
|
1739 | } |
1732 | } |
1740 | } |
1733 | } |
1741 | |
1734 | |
1742 | if (flag != SK_EXP_SKILL_ONLY) |
1735 | if (flag != SK_EXP_SKILL_ONLY) |
1743 | { |
1736 | { |
… | |
… | |
1809 | if (exp < 0) |
1802 | if (exp < 0) |
1810 | return check_exp_loss (op, exp); |
1803 | return check_exp_loss (op, exp); |
1811 | else |
1804 | else |
1812 | return MIN (exp, (sint64) MAX_EXPERIENCE - op->stats.exp); |
1805 | return MIN (exp, (sint64) MAX_EXPERIENCE - op->stats.exp); |
1813 | } |
1806 | } |
1814 | |
|
|
1815 | |
1807 | |
1816 | /* Subtracts experience from player. |
1808 | /* Subtracts experience from player. |
1817 | * if skill is set and flag == SK_SUBTRACT_SKILL_EXP, then we |
1809 | * if skill is set and flag == SK_SUBTRACT_SKILL_EXP, then we |
1818 | * only subtract from the matching skill. Otherwise, |
1810 | * only subtract from the matching skill. Otherwise, |
1819 | * this subtracts a portion from all |
1811 | * this subtracts a portion from all |
… | |
… | |
1833 | sint64 del_exp; |
1825 | sint64 del_exp; |
1834 | |
1826 | |
1835 | for (tmp = op->inv; tmp; tmp = tmp->below) |
1827 | for (tmp = op->inv; tmp; tmp = tmp->below) |
1836 | if (tmp->type == SKILL && tmp->stats.exp) |
1828 | if (tmp->type == SKILL && tmp->stats.exp) |
1837 | { |
1829 | { |
1838 | if (flag == SK_SUBTRACT_SKILL_EXP && skill && !strcmp (tmp->skill, skill)) |
1830 | if (flag == SK_SUBTRACT_SKILL_EXP && skill && !strcmp (&tmp->skill, skill)) |
1839 | { |
1831 | { |
1840 | del_exp = check_exp_loss (tmp, exp); |
1832 | del_exp = check_exp_loss (tmp, exp); |
1841 | tmp->stats.exp -= del_exp; |
1833 | tmp->stats.exp -= del_exp; |
1842 | player_lvl_adj (op, tmp); |
1834 | player_lvl_adj (op, tmp); |
1843 | } |
1835 | } |