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.1 by root, Fri Feb 3 07:11:32 2006 UTC vs.
Revision 1.6 by elmex, Wed Mar 15 15:35:46 2006 UTC

1/* 1/*
2 * static char *rcsid_living_c = 2 * static char *rcsid_living_c =
3 * "$Id: living.c,v 1.1 2006/02/03 07:11:32 root Exp $"; 3 * "$Id: living.c,v 1.6 2006/03/15 15:35:46 elmex Exp $";
4 */ 4 */
5 5
6/* 6/*
7 CrossFire, A Multiplayer game for X-windows 7 CrossFire, A Multiplayer game for X-windows
8 8
308/* 308/*
309 * returns the specified stat. See also set_attr_value(). 309 * returns the specified stat. See also set_attr_value().
310 */ 310 */
311 311
312sint8 312sint8
313get_attr_value(living *stats,int attr) { 313get_attr_value(const living *stats,int attr) {
314 switch(attr) { 314 switch(attr) {
315 case STR: 315 case STR:
316 return(stats->Str); 316 return(stats->Str);
317 case DEX: 317 case DEX:
318 return(stats->Dex); 318 return(stats->Dex);
1372 * check if the stat becomes negative, thus this function 1372 * check if the stat becomes negative, thus this function
1373 * merely checks that all stats are 1 or more, and returns 1373 * merely checks that all stats are 1 or more, and returns
1374 * false otherwise. 1374 * false otherwise.
1375 */ 1375 */
1376 1376
1377int allowed_class(object *op) { 1377int allowed_class(const object *op) {
1378 return op->stats.Dex>0&&op->stats.Str>0&&op->stats.Con>0&& 1378 return op->stats.Dex>0&&op->stats.Str>0&&op->stats.Con>0&&
1379 op->stats.Int>0&&op->stats.Wis>0&&op->stats.Pow>0&& 1379 op->stats.Int>0&&op->stats.Wis>0&&op->stats.Pow>0&&
1380 op->stats.Cha>0; 1380 op->stats.Cha>0;
1381} 1381}
1382 1382
1388 * Note that the title is written to 'own_title' in the 1388 * Note that the title is written to 'own_title' in the
1389 * player struct. This should be changed to 'ext_title' 1389 * player struct. This should be changed to 'ext_title'
1390 * as soon as clients support this! 1390 * as soon as clients support this!
1391 * Please, anyone, write support for 'ext_title'. 1391 * Please, anyone, write support for 'ext_title'.
1392 */ 1392 */
1393void set_dragon_name(object *pl, object *abil, object *skin) { 1393void set_dragon_name(object *pl, const object *abil, const object *skin) {
1394 int atnr=-1; /* attacknumber of highest level */ 1394 int atnr=-1; /* attacknumber of highest level */
1395 int level=0; /* highest level */ 1395 int level=0; /* highest level */
1396 int i; 1396 int i;
1397 1397
1398 /* Perhaps do something more clever? */ 1398 /* Perhaps do something more clever? */
1591 */ 1591 */
1592void calc_perm_exp(object *op) 1592void calc_perm_exp(object *op)
1593{ 1593{
1594 int p_exp_min; 1594 int p_exp_min;
1595 1595
1596 /* Ensure that our permanent experience minimum is met. */ 1596 /* Ensure that our permanent experience minimum is met.
1597 p_exp_min = (int)(PERM_EXP_MINIMUM_RATIO * (float)(op->stats.exp)); 1597 * permenent_exp_ratio is an integer percentage, we divide by 100
1598 * to get the fraction */
1599 p_exp_min = (int)(settings.permanent_exp_ratio * (float)(op->stats.exp)/100);
1598 1600
1599 if (op->perm_exp < p_exp_min) 1601 if (op->perm_exp < p_exp_min)
1600 op->perm_exp = p_exp_min; 1602 op->perm_exp = p_exp_min;
1601 1603
1602 /* Cap permanent experience. */ 1604 /* Cap permanent experience. */
1658 exp_to_add = exp; 1660 exp_to_add = exp;
1659 limit=(levels[op->level+1]-levels[op->level])/2; 1661 limit=(levels[op->level+1]-levels[op->level])/2;
1660 if (exp_to_add > limit) exp_to_add=limit; 1662 if (exp_to_add > limit) exp_to_add=limit;
1661 1663
1662 ADD_EXP(op->stats.exp, (float) exp_to_add * (skill_obj? skill_obj->expmul:1)); 1664 ADD_EXP(op->stats.exp, (float) exp_to_add * (skill_obj? skill_obj->expmul:1));
1663 if (settings.use_permanent_experience) { 1665 if (settings.permanent_exp_ratio) {
1664 ADD_EXP(op->perm_exp, (float) exp_to_add * PERM_EXP_GAIN_RATIO * (skill_obj? skill_obj->expmul:1)); 1666 ADD_EXP(op->perm_exp, (float) exp_to_add * PERM_EXP_GAIN_RATIO * (skill_obj? skill_obj->expmul:1));
1665 calc_perm_exp(op); 1667 calc_perm_exp(op);
1666 } 1668 }
1667 1669
1668 player_lvl_adj(op,NULL); 1670 player_lvl_adj(op,NULL);
1669 if (skill_obj) { 1671 if (skill_obj) {
1670 exp_to_add = exp; 1672 exp_to_add = exp;
1671 limit=(levels[skill_obj->level+1]-levels[skill_obj->level])/2; 1673 limit=(levels[skill_obj->level+1]-levels[skill_obj->level])/2;
1672 if (exp_to_add > limit) exp_to_add=limit; 1674 if (exp_to_add > limit) exp_to_add=limit;
1673 ADD_EXP(skill_obj->stats.exp, exp_to_add); 1675 ADD_EXP(skill_obj->stats.exp, exp_to_add);
1674 if (settings.use_permanent_experience) { 1676 if (settings.permanent_exp_ratio) {
1675 skill_obj->perm_exp += exp_to_add * PERM_EXP_GAIN_RATIO; 1677 skill_obj->perm_exp += exp_to_add * PERM_EXP_GAIN_RATIO;
1676 calc_perm_exp(skill_obj); 1678 calc_perm_exp(skill_obj);
1677 } 1679 }
1678 player_lvl_adj(op,skill_obj); 1680 player_lvl_adj(op,skill_obj);
1679 } 1681 }
1685 * adjustments based on permanent exp and the like. 1687 * adjustments based on permanent exp and the like.
1686 * This function should always be used for losing experience - 1688 * This function should always be used for losing experience -
1687 * the 'exp' value passed should be positive - this is the 1689 * the 'exp' value passed should be positive - this is the
1688 * amount that should get subtract from the player. 1690 * amount that should get subtract from the player.
1689 */ 1691 */
1690sint64 check_exp_loss(object *op, sint64 exp) 1692sint64 check_exp_loss(const object *op, sint64 exp)
1691{ 1693{
1692 sint64 del_exp; 1694 sint64 del_exp;
1693 1695
1694 if (exp > op->stats.exp) exp = op->stats.exp; 1696 if (exp > op->stats.exp) exp = op->stats.exp;
1695 if (settings.use_permanent_experience) { 1697 if (settings.permanent_exp_ratio) {
1696 del_exp = (op->stats.exp - op->perm_exp) * PERM_EXP_MAX_LOSS_RATIO; 1698 del_exp = (op->stats.exp - op->perm_exp) * PERM_EXP_MAX_LOSS_RATIO;
1697 if (del_exp < 0) del_exp = 0; 1699 if (del_exp < 0) del_exp = 0;
1698 if (exp > del_exp) exp=del_exp; 1700 if (exp > del_exp) exp=del_exp;
1699 } 1701 }
1700 return exp; 1702 return exp;
1701} 1703}
1702 1704
1703sint64 check_exp_adjust(object *op, sint64 exp) 1705sint64 check_exp_adjust(const object *op, sint64 exp)
1704{ 1706{
1705 if (exp<0) return check_exp_loss(op, exp); 1707 if (exp<0) return check_exp_loss(op, exp);
1706 else return MIN(exp, MAX_EXPERIENCE - op->stats.exp); 1708 else return MIN(exp, MAX_EXPERIENCE - op->stats.exp);
1707} 1709}
1708 1710
1811 subtract_player_exp(op, FABS(exp), skill_name, flag); 1813 subtract_player_exp(op, FABS(exp), skill_name, flag);
1812 1814
1813 } 1815 }
1814} 1816}
1815 1817
1816/* Applies a death penalty experience. 20% or 3 levels, whichever is 1818/* Applies a death penalty experience, the size of this is defined by the
1817 * less experience lost. 1819 * settings death_penalty_percentage and death_penalty_levels, and by the
1820 * amount of permenent experience, whichever gives the lowest loss.
1818 */ 1821 */
1819 1822
1820void apply_death_exp_penalty(object *op) { 1823void apply_death_exp_penalty(object *op) {
1821 object *tmp; 1824 object *tmp;
1822 sint64 loss; 1825 sint64 loss;
1823 sint64 loss_20p; /* 20 percent experience loss */ 1826 sint64 percentage_loss; /* defined by the setting 'death_penalty_percent' */
1824 sint64 loss_3l; /* 3 level experience loss */ 1827 sint64 level_loss; /* defined by the setting 'death_penalty_levels */
1825 1828
1826 for(tmp=op->inv;tmp;tmp=tmp->below) 1829 for(tmp=op->inv;tmp;tmp=tmp->below)
1827 if(tmp->type==SKILL && tmp->stats.exp) { 1830 if(tmp->type==SKILL && tmp->stats.exp) {
1828 1831
1829 loss_20p = tmp->stats.exp * 0.20; 1832 percentage_loss = tmp->stats.exp * settings.death_penalty_ratio/100;
1830 loss_3l = tmp->stats.exp - levels[MAX(0,tmp->level -3)]; 1833 level_loss = tmp->stats.exp - levels[MAX(0,tmp->level - settings.death_penalty_level)];
1831 1834
1832 /* With the revised exp system, you can get cases where 1835 /* With the revised exp system, you can get cases where
1833 * losing 3 levels would still require that you have more 1836 * losing several levels would still require that you have more
1834 * exp than you current have - this is true if the levels 1837 * exp than you currently have - this is true if the levels
1835 * tables is a lot harder. 1838 * tables is a lot harder.
1836 */ 1839 */
1837 if (loss_3l < 0) loss_3l = 0; 1840 if (level_loss < 0) level_loss = 0;
1838 1841
1839 loss = check_exp_loss(tmp, MIN(loss_3l, loss_20p)); 1842 loss = check_exp_loss(tmp, MIN(level_loss, percentage_loss));
1840 1843
1841 tmp->stats.exp -= loss; 1844 tmp->stats.exp -= loss;
1842 player_lvl_adj(op,tmp); 1845 player_lvl_adj(op,tmp);
1843 } 1846 }
1844 1847
1845 loss_20p = op->stats.exp * 0.20; 1848 percentage_loss = op->stats.exp * settings.death_penalty_ratio/100;
1846 loss_3l = op->stats.exp - levels[MAX(0,op->level -3)]; 1849 level_loss = op->stats.exp - levels[MAX(0,op->level - settings.death_penalty_level)];
1847 if (loss_3l < 0) loss_3l = 0; 1850 if (level_loss < 0) level_loss = 0;
1848 loss = check_exp_loss(op, MIN(loss_3l, loss_20p)); 1851 loss = check_exp_loss(op, MIN(level_loss, percentage_loss));
1849 1852
1850 op->stats.exp -= loss; 1853 op->stats.exp -= loss;
1851 player_lvl_adj(op,NULL); 1854 player_lvl_adj(op,NULL);
1852} 1855}
1853 1856
1856 * save_throw table. level is the effective level to make 1859 * save_throw table. level is the effective level to make
1857 * the save at, and bonus is any plus/bonus (typically based on 1860 * the save at, and bonus is any plus/bonus (typically based on
1858 * resistance to particular attacktype. 1861 * resistance to particular attacktype.
1859 * Returns 1 if op makes his save, 0 if he failed 1862 * Returns 1 if op makes his save, 0 if he failed
1860 */ 1863 */
1861int did_make_save(object *op, int level, int bonus) 1864int did_make_save(const object *op, int level, int bonus)
1862{ 1865{
1863 if (level > MAX_SAVE_LEVEL) level = MAX_SAVE_LEVEL; 1866 if (level > MAX_SAVE_LEVEL) level = MAX_SAVE_LEVEL;
1864 1867
1865 if ((random_roll(1, 20, op, PREFER_HIGH) + bonus) < savethrow[level]) 1868 if ((random_roll(1, 20, op, PREFER_HIGH) + bonus) < savethrow[level])
1866 return 0; 1869 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines