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

Comparing deliantra/server/common/living.C (file contents):
Revision 1.85 by root, Sun May 4 19:14:23 2008 UTC vs.
Revision 1.96 by elmex, Mon Jan 12 00:17:22 2009 UTC

400 /* MOVE_FLY_HIGH trumps MOVE_FLY_LOW - changing your move_fly_low 400 /* MOVE_FLY_HIGH trumps MOVE_FLY_LOW - changing your move_fly_low
401 * status doesn't make a difference if you are flying high 401 * status doesn't make a difference if you are flying high
402 */ 402 */
403 if (tmp->move_type & MOVE_FLY_LOW && !(op->move_type & MOVE_FLY_HIGH)) 403 if (tmp->move_type & MOVE_FLY_LOW && !(op->move_type & MOVE_FLY_HIGH))
404 { 404 {
405 DIFF_MSG (flag, "You start to float in the air!.", "You float down to the ground."); 405 DIFF_MSG (flag, "You start to float in the air!", "You float down to the ground.");
406 } 406 }
407 407
408 if (tmp->move_type & MOVE_FLY_HIGH) 408 if (tmp->move_type & MOVE_FLY_HIGH)
409 { 409 {
410 /* double conditional - second case covers if you have move_fly_low - 410 /* double conditional - second case covers if you have move_fly_low -
858 * then calls this function. 858 * then calls this function.
859 */ 859 */
860 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type == POTION) 860 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type == POTION)
861 continue; 861 continue;
862 862
863 /* See note in map.c:update_position about making this additive
864 * since light sources are never applied, need to put check here.
865 */
866 glow_radius = max (glow_radius, tmp->glow_radius); 863 glow_radius += tmp->glow_radius;
867 864
868 /* For some things, we don't care what is equipped */ 865 /* For some things, we don't care what is equipped */
869 if (tmp->type == SKILL) 866 if (tmp->type == SKILL)
870 { 867 {
871 /* Want to take the highest skill here. */ 868 /* Want to take the highest skill here. */
917 914
918 if (digest_types [tmp->type]) 915 if (digest_types [tmp->type])
919 { 916 {
920 contr->digestion += tmp->stats.food; 917 contr->digestion += tmp->stats.food;
921 contr->gen_hp += tmp->stats.hp; 918 contr->gen_hp += tmp->stats.hp;
919 if (tmp->type != BOW) // ugly exception for bows
922 contr->gen_sp += tmp->stats.sp; 920 contr->gen_sp += tmp->stats.sp;
923 contr->gen_grace += tmp->stats.grace; 921 contr->gen_grace += tmp->stats.grace;
924 contr->gen_sp_armour += tmp->gen_sp_armour; 922 contr->gen_sp_armour += tmp->gen_sp_armour;
925 } 923 }
926 } /* if this is a player */ 924 } /* if this is a player */
927 else 925 else
1136 else /* To nullify the below effect */ 1134 else /* To nullify the below effect */
1137 ac += tmp->stats.ac + tmp->magic; 1135 ac += tmp->stats.ac + tmp->magic;
1138 } 1136 }
1139 1137
1140 if (tmp->stats.wc) 1138 if (tmp->stats.wc)
1141 wc -= (tmp->stats.wc + tmp->magic); 1139 wc -= tmp->stats.wc + tmp->magic;
1142 1140
1143 if (tmp->stats.ac) 1141 if (tmp->stats.ac)
1144 ac -= (tmp->stats.ac + tmp->magic); 1142 ac -= tmp->stats.ac + tmp->magic;
1145 1143
1146 if (ARMOUR_SPEED (tmp)) 1144 if (ARMOUR_SPEED (tmp))
1147 max_speed = min (max_speed, ARMOUR_SPEED (tmp) / 10.f); 1145 max_speed = min (max_speed, ARMOUR_SPEED (tmp) / 10.f);
1148 1146
1149 break; 1147 break;
1150 } /* switch tmp->type */ 1148 } /* switch tmp->type */
1151 } /* item is equipped */ 1149 } /* item is equipped */
1152 } /* for loop of items */ 1150 } /* for loop of items */
1151
1152 glow_radius = min (glow_radius, MAX_LIGHT_RADIUS);
1153 1153
1154 /* We've gone through all the objects the player has equipped. For many things, we 1154 /* We've gone through all the objects the player has equipped. For many things, we
1155 * have generated intermediate values which we now need to assign. 1155 * have generated intermediate values which we now need to assign.
1156 */ 1156 */
1157 1157
1418 // update the mapspace, if we are on a map 1418 // update the mapspace, if we are on a map
1419 if (!flag [FLAG_REMOVED] && map) 1419 if (!flag [FLAG_REMOVED] && map)
1420 map->at (x, y).flags_ = 0; 1420 map->at (x, y).flags_ = 0;
1421} 1421}
1422 1422
1423void
1424object::set_glow_radius (sint8 rad)
1425{
1426 glow_radius = rad;
1427
1428 if (is_on_map ())
1429 update_all_los (map, x, y);
1430 else if (object *env = outer_env ())
1431 {
1432 env->update_stats ();
1433
1434 if (env->is_on_map ())
1435 update_all_los (env->map, env->x, env->y);
1436 }
1437}
1438
1423/* 1439/*
1424 * Returns true if the given player is a legal class. 1440 * Returns true if the given player is a legal class.
1425 * The function to add and remove class-bonuses to the stats doesn't 1441 * The function to add and remove class-bonuses to the stats doesn't
1426 * check if the stat becomes negative, thus this function 1442 * check if the stat becomes negative, thus this function
1427 * merely checks that all stats are 1 or more, and returns 1443 * merely checks that all stats are 1 or more, and returns
1441 1457
1442/* 1458/*
1443 * set the new dragon name after gaining levels or 1459 * set the new dragon name after gaining levels or
1444 * changing ability focus (later this can be extended to 1460 * changing ability focus (later this can be extended to
1445 * eventually change the player's face and animation) 1461 * eventually change the player's face and animation)
1446 *
1447 * Note that the title is written to 'own_title' in the
1448 * player struct. This should be changed to 'ext_title'
1449 * as soon as clients support this!
1450 * Please, anyone, write support for 'ext_title'.
1451 */ 1462 */
1452void 1463void
1453set_dragon_name (object *pl, const object *abil, const object *skin) 1464set_dragon_name (object *pl, const object *abil, const object *skin)
1454{ 1465{
1455 int atnr = -1; /* attacknumber of highest level */ 1466 int atnr = -1; /* attacknumber of highest level */
1473 /* now if there are equals at highest level, pick the one with focus, 1484 /* now if there are equals at highest level, pick the one with focus,
1474 or else at random */ 1485 or else at random */
1475 if (atnr_is_dragon_enabled (abil->stats.exp) && abil->resist[abil->stats.exp] >= level) 1486 if (atnr_is_dragon_enabled (abil->stats.exp) && abil->resist[abil->stats.exp] >= level)
1476 atnr = abil->stats.exp; 1487 atnr = abil->stats.exp;
1477 1488
1478 level = (int) (level / 25.);
1479
1480 /* now set the new title */ 1489 /* now set the new title */
1481 if (pl->contr)
1482 {
1483 if (level == 0)
1484 sprintf (pl->contr->title, "%s hatchling", attacks[atnr]); 1490 if (level < 25) sprintf (pl->contr->title, "%s hatchling", attacks[atnr]);
1485 else if (level == 1)
1486 sprintf (pl->contr->title, "%s wyrm", attacks[atnr]); 1491 else if (level < 50) sprintf (pl->contr->title, "%s wyrm" , attacks[atnr]);
1487 else if (level == 2)
1488 sprintf (pl->contr->title, "%s wyvern", attacks[atnr]); 1492 else if (level < 75) sprintf (pl->contr->title, "%s wyvern" , attacks[atnr]);
1489 else if (level == 3)
1490 sprintf (pl->contr->title, "%s dragon", attacks[atnr]); 1493 else if (level < 100) sprintf (pl->contr->title, "%s dragon" , attacks[atnr]);
1491 else 1494 else
1492 { 1495 {
1493 /* special titles for extra high resistance! */ 1496 /* special titles for extra high resistance! */
1494 if (skin->resist[atnr] > 80)
1495 sprintf (pl->contr->title, "legendary %s dragon", attacks[atnr]); 1497 if (skin->resist[atnr] > 80) sprintf (pl->contr->title, "legendary %s dragon", attacks[atnr]);
1496 else if (skin->resist[atnr] > 50)
1497 sprintf (pl->contr->title, "ancient %s dragon", attacks[atnr]); 1498 else if (skin->resist[atnr] > 50) sprintf (pl->contr->title, "ancient %s dragon" , attacks[atnr]);
1498 else
1499 sprintf (pl->contr->title, "big %s dragon", attacks[atnr]); 1499 else sprintf (pl->contr->title, "big %s dragon" , attacks[atnr]);
1500 }
1501 } 1500 }
1502 1501
1503 strcpy (pl->contr->own_title, ""); 1502 strcpy (pl->contr->own_title, "");
1504} 1503}
1505 1504
1572 object *skill_obj; 1571 object *skill_obj;
1573 1572
1574 skill_obj = get_archetype_by_skill_name (skill_name, SKILL); 1573 skill_obj = get_archetype_by_skill_name (skill_name, SKILL);
1575 if (!skill_obj) 1574 if (!skill_obj)
1576 { 1575 {
1577 LOG (llevError, "add_player_exp: couldn't find skill %s\n", skill_name); 1576 LOG (llevError, "give_skill_by_name: couldn't find skill %s\n", skill_name);
1578 return NULL; 1577 return NULL;
1579 } 1578 }
1580 1579
1581 /* clear the flag - exp goes into this bucket, but player 1580 /* clear the flag - exp goes into this bucket, but player
1582 * still doesn't know it. 1581 * still doesn't know it.
1583 */ 1582 */
1584 CLEAR_FLAG (skill_obj, FLAG_CAN_USE_SKILL); 1583 CLEAR_FLAG (skill_obj, FLAG_CAN_USE_SKILL);
1585 skill_obj->stats.exp = 0; 1584 skill_obj->stats.exp = 0;
1586 skill_obj->level = 1; 1585 skill_obj->level = 1;
1587 insert_ob_in_ob (skill_obj, op); 1586 op->insert (skill_obj);
1588 1587
1589 if (player *pl = op->contr) 1588 if (player *pl = op->contr)
1590 { 1589 pl->link_skills ();
1591 pl->last_skill_ob [skill_obj->subtype] = skill_obj;
1592 if (pl->ns)
1593 pl->ns->last_skill_exp[skill_obj->subtype] = -1;//TODO: should be made superfluous
1594 }
1595 1590
1596 return skill_obj; 1591 return skill_obj;
1597} 1592}
1598 1593
1599/* player_lvl_adj() - for the new exp system. we are concerned with 1594/* player_lvl_adj() - for the new exp system. we are concerned with
1718 * flag is what to do if the player doesn't have the skill: 1713 * flag is what to do if the player doesn't have the skill:
1719 */ 1714 */
1720static void 1715static void
1721add_player_exp (object *op, sint64 exp, const char *skill_name, int flag) 1716add_player_exp (object *op, sint64 exp, const char *skill_name, int flag)
1722{ 1717{
1723 object *skill_obj = NULL; 1718 object *skill_obj;
1724 sint64 limit, exp_to_add; 1719 sint64 limit, exp_to_add;
1725 int i; 1720 int i;
1726 1721
1727 /* prevents some forms of abuse. */ 1722 /* prevents some forms of abuse. */
1728 if (op->contr->braced) 1723 if (op->contr->braced)
1731 /* Try to find the matching skill. 1726 /* Try to find the matching skill.
1732 * We do a shortcut/time saving mechanism first - see if it matches 1727 * We do a shortcut/time saving mechanism first - see if it matches
1733 * chosen_skill. This means we don't need to search through 1728 * chosen_skill. This means we don't need to search through
1734 * the players inventory. 1729 * the players inventory.
1735 */ 1730 */
1731 skill_obj = 0;
1732
1736 if (skill_name) 1733 if (skill_name)
1737 { 1734 {
1738 if (op->chosen_skill && op->chosen_skill->type == SKILL && !strcmp (skill_name, op->chosen_skill->skill)) 1735 skill_obj = op->contr->find_skill (skill_name);
1739 skill_obj = op->chosen_skill;
1740 else
1741 {
1742 for (i = 0; i < NUM_SKILLS; i++)
1743 if (op->contr->last_skill_ob[i] && !strcmp (op->contr->last_skill_ob[i]->skill, skill_name))
1744 {
1745 skill_obj = op->contr->last_skill_ob[i];
1746 break;
1747 }
1748 1736
1749 /* Player doesn't have the skill. Check to see what to do, and give 1737 /* Player doesn't have the skill. Check to see what to do, and give
1750 * it to the player if necessary 1738 * it to the player if necessary
1751 */ 1739 */
1752 if (!skill_obj) 1740 if (!skill_obj)
1753 { 1741 {
1754 if (flag == SK_EXP_NONE) 1742 if (flag == SK_EXP_NONE)
1755 return; 1743 return;
1744
1756 else if (flag == SK_EXP_ADD_SKILL) 1745 if (flag == SK_EXP_ADD_SKILL)
1757 give_skill_by_name (op, skill_name); 1746 skill_obj = give_skill_by_name (op, skill_name);
1758 }
1759 } 1747 }
1760 } 1748 }
1761 1749
1762 if (flag != SK_EXP_SKILL_ONLY) 1750 if (flag != SK_EXP_SKILL_ONLY)
1763 { 1751 {
1796 player_lvl_adj (op, skill_obj); 1784 player_lvl_adj (op, skill_obj);
1797 } 1785 }
1798} 1786}
1799 1787
1800/* This function checks to make sure that object 'op' can 1788/* This function checks to make sure that object 'op' can
1801 * lost 'exp' experience. It returns the amount of exp 1789 * lose 'exp' experience. It returns the amount of exp
1802 * object 'op' can in fact lose - it basically makes 1790 * object 'op' can in fact lose - it basically makes
1803 * adjustments based on permanent exp and the like. 1791 * adjustments based on permanent exp and the like.
1804 * This function should always be used for losing experience - 1792 * This function should always be used for losing experience -
1805 * the 'exp' value passed should be positive - this is the 1793 * the 'exp' value passed should be positive - this is the
1806 * amount that should get subtract from the player. 1794 * amount that should get subtract from the player.
1810{ 1798{
1811 sint64 del_exp; 1799 sint64 del_exp;
1812 1800
1813 if (exp > op->stats.exp) 1801 if (exp > op->stats.exp)
1814 exp = op->stats.exp; 1802 exp = op->stats.exp;
1803
1815 if (settings.permanent_exp_ratio) 1804 if (settings.permanent_exp_ratio)
1816 { 1805 {
1817 del_exp = (sint64) ((op->stats.exp - op->perm_exp) * PERM_EXP_MAX_LOSS_RATIO); 1806 del_exp = (sint64) ((op->stats.exp - op->perm_exp) * PERM_EXP_MAX_LOSS_RATIO);
1807
1818 if (del_exp < 0) 1808 if (del_exp < 0)
1819 del_exp = 0; 1809 del_exp = 0;
1810
1820 if (exp > del_exp) 1811 if (exp > del_exp)
1821 exp = del_exp; 1812 exp = del_exp;
1822 } 1813 }
1814
1823 return exp; 1815 return exp;
1824} 1816}
1825 1817
1826sint64 1818sint64
1827check_exp_adjust (const object *op, sint64 exp) 1819check_exp_adjust (const object *op, sint64 exp)
1828{ 1820{
1829 if (exp < 0) 1821 if (exp < 0)
1830 return check_exp_loss (op, exp); 1822 return check_exp_loss (op, exp);
1831 else 1823 else
1832 return MIN (exp, (sint64) MAX_EXPERIENCE - op->stats.exp); 1824 return min (exp, (sint64)MAX_EXPERIENCE - op->stats.exp);
1833} 1825}
1834
1835 1826
1836/* Subtracts experience from player. 1827/* Subtracts experience from player.
1837 * if skill is set and flag == SK_SUBTRACT_SKILL_EXP, then we 1828 * if skill is set and flag == SK_SUBTRACT_SKILL_EXP, then we
1838 * only subtract from the matching skill. Otherwise, 1829 * only subtract from the matching skill. Otherwise,
1839 * this subtracts a portion from all 1830 * this subtracts a portion from all
1853 sint64 del_exp; 1844 sint64 del_exp;
1854 1845
1855 for (tmp = op->inv; tmp; tmp = tmp->below) 1846 for (tmp = op->inv; tmp; tmp = tmp->below)
1856 if (tmp->type == SKILL && tmp->stats.exp) 1847 if (tmp->type == SKILL && tmp->stats.exp)
1857 { 1848 {
1858 if (flag == SK_SUBTRACT_SKILL_EXP && skill && !strcmp (tmp->skill, skill)) 1849 if (flag == SK_SUBTRACT_SKILL_EXP && skill && !strcmp (&tmp->skill, skill))
1859 { 1850 {
1860 del_exp = check_exp_loss (tmp, exp); 1851 del_exp = check_exp_loss (tmp, exp);
1861 tmp->stats.exp -= del_exp; 1852 tmp->stats.exp -= del_exp;
1862 player_lvl_adj (op, tmp); 1853 player_lvl_adj (op, tmp);
1863 } 1854 }
1951 * amount of permenent experience, whichever gives the lowest loss. 1942 * amount of permenent experience, whichever gives the lowest loss.
1952 */ 1943 */
1953void 1944void
1954apply_death_exp_penalty (object *op) 1945apply_death_exp_penalty (object *op)
1955{ 1946{
1956 object *tmp;
1957 sint64 loss; 1947 sint64 loss;
1958 sint64 percentage_loss; /* defined by the setting 'death_penalty_percent' */ 1948 sint64 percentage_loss; /* defined by the setting 'death_penalty_percent' */
1959 sint64 level_loss; /* defined by the setting 'death_penalty_levels */ 1949 sint64 level_loss; /* defined by the setting 'death_penalty_levels */
1960 1950
1961 for (tmp = op->inv; tmp; tmp = tmp->below) 1951 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1962 if (tmp->type == SKILL && tmp->stats.exp) 1952 if (tmp->type == SKILL && tmp->stats.exp)
1963 { 1953 {
1964
1965 percentage_loss = tmp->stats.exp * settings.death_penalty_ratio / 100; 1954 percentage_loss = tmp->stats.exp * settings.death_penalty_ratio / 100;
1966 level_loss = tmp->stats.exp - levels[MAX (0, tmp->level - settings.death_penalty_level)]; 1955 level_loss = tmp->stats.exp - levels[MAX (0, tmp->level - settings.death_penalty_level)];
1967 1956
1968 /* With the revised exp system, you can get cases where 1957 /* With the revised exp system, you can get cases where
1969 * losing several levels would still require that you have more 1958 * losing several levels would still require that you have more
1971 * tables is a lot harder. 1960 * tables is a lot harder.
1972 */ 1961 */
1973 if (level_loss < 0) 1962 if (level_loss < 0)
1974 level_loss = 0; 1963 level_loss = 0;
1975 1964
1976 loss = check_exp_loss (tmp, MIN (level_loss, percentage_loss)); 1965 loss = check_exp_loss (tmp, min (level_loss, percentage_loss));
1977 1966
1978 tmp->stats.exp -= loss; 1967 tmp->stats.exp -= loss;
1979 player_lvl_adj (op, tmp); 1968 player_lvl_adj (op, tmp);
1980 } 1969 }
1981 1970
1982 percentage_loss = op->stats.exp * settings.death_penalty_ratio / 100; 1971 percentage_loss = op->stats.exp * settings.death_penalty_ratio / 100;
1983 level_loss = op->stats.exp - levels[MAX (0, op->level - settings.death_penalty_level)]; 1972 level_loss = op->stats.exp - levels[max (0, op->level - settings.death_penalty_level)];
1984 1973
1985 if (level_loss < 0) 1974 if (level_loss < 0)
1986 level_loss = 0; 1975 level_loss = 0;
1976
1987 loss = check_exp_loss (op, MIN (level_loss, percentage_loss)); 1977 loss = check_exp_loss (op, min (level_loss, percentage_loss));
1988 1978
1989 op->stats.exp -= loss; 1979 op->stats.exp -= loss;
1990 player_lvl_adj (op, NULL); 1980 player_lvl_adj (op, NULL);
1991} 1981}
1992 1982

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines