--- deliantra/server/common/living.C 2006/08/29 08:01:35 1.3 +++ deliantra/server/common/living.C 2006/09/01 17:16:47 1.4 @@ -1,6 +1,6 @@ /* * static char *rcsid_living_c = - * "$Id: living.C,v 1.3 2006/08/29 08:01:35 root Exp $"; + * "$Id: living.C,v 1.4 2006/09/01 17:16:47 elmex Exp $"; */ /* @@ -1614,67 +1614,89 @@ * flag is what to do if the player doesn't have the skill: */ -static void add_player_exp(object *op, sint64 exp, const char *skill_name, int flag) +static void add_player_exp (object * op, sint64 exp, const char *skill_name, int flag) { - object *skill_obj=NULL; - sint64 limit, exp_to_add; - int i; - - /* prevents some forms of abuse. */ - if(op->contr->braced) exp=exp/5; - - /* Try to find the matching skill. - * We do a shortcut/time saving mechanism first - see if it matches - * chosen_skill. This means we don't need to search through - * the players inventory. - */ - if (skill_name) { - if (op->chosen_skill && op->chosen_skill->type == SKILL && - !strcmp(skill_name, op->chosen_skill->skill)) - skill_obj = op->chosen_skill; - else { - for (i=0; icontr->last_skill_ob[i] && - !strcmp(op->contr->last_skill_ob[i]->skill, skill_name)) { - skill_obj = op->contr->last_skill_ob[i]; - break; - } + object *skill_obj = NULL; + sint64 limit, exp_to_add; + int i; - /* Player doesn't have the skill. Check to see what to do, and give - * it to the player if necessary - */ - if (!skill_obj) { - if (flag == SK_EXP_NONE) return; - else if (flag == SK_EXP_ADD_SKILL) - give_skill_by_name(op, skill_name); + /* prevents some forms of abuse. */ + if (op->contr->braced) + exp = exp / 5; + + /* Try to find the matching skill. + * We do a shortcut/time saving mechanism first - see if it matches + * chosen_skill. This means we don't need to search through + * the players inventory. + */ + if (skill_name) + { + if (op->chosen_skill && op->chosen_skill->type == SKILL && + !strcmp (skill_name, op->chosen_skill->skill)) + skill_obj = op->chosen_skill; + else + { + for (i = 0; i < NUM_SKILLS; i++) + if (op->contr->last_skill_ob[i] && + !strcmp (op->contr->last_skill_ob[i]->skill, skill_name)) + { + skill_obj = op->contr->last_skill_ob[i]; + break; + } + + /* Player doesn't have the skill. Check to see what to do, and give + * it to the player if necessary + */ + if (!skill_obj) + { + if (flag == SK_EXP_NONE) + return; + else if (flag == SK_EXP_ADD_SKILL) + give_skill_by_name (op, skill_name); } } } - /* Basically, you can never gain more experience in one shot - * than half what you need to gain for next level. - */ - exp_to_add = exp; - limit=(levels[op->level+1]-levels[op->level])/2; - if (exp_to_add > limit) exp_to_add=limit; - - ADD_EXP(op->stats.exp, (sint64) ((float) exp_to_add * (skill_obj? skill_obj->expmul:1))); - if (settings.permanent_exp_ratio) { - ADD_EXP(op->perm_exp, (sint64) ((float) exp_to_add * PERM_EXP_GAIN_RATIO * (skill_obj? skill_obj->expmul:1))); - calc_perm_exp(op); - } - - player_lvl_adj(op,NULL); - if (skill_obj) { - exp_to_add = exp; - limit=(levels[skill_obj->level+1]-levels[skill_obj->level])/2; - if (exp_to_add > limit) exp_to_add=limit; - ADD_EXP(skill_obj->stats.exp, exp_to_add); - if (settings.permanent_exp_ratio) { - skill_obj->perm_exp += (sint64) ((float) exp_to_add * PERM_EXP_GAIN_RATIO); - calc_perm_exp(skill_obj); + if (flag != SK_EXP_SKILL_ONLY) + { + /* Basically, you can never gain more experience in one shot + * than half what you need to gain for next level. + */ + exp_to_add = exp; + limit = (levels[op->level + 1] - levels[op->level]) / 2; + if (exp_to_add > limit) + exp_to_add = limit; + + ADD_EXP (op->stats.exp, + (sint64) ((float) exp_to_add * + (skill_obj ? skill_obj->expmul : 1))); + if (settings.permanent_exp_ratio) + { + ADD_EXP (op->perm_exp, + (sint64) ((float) exp_to_add * PERM_EXP_GAIN_RATIO * + (skill_obj ? skill_obj->expmul : 1))); + calc_perm_exp (op); + } + + player_lvl_adj (op, NULL); + } + + if (skill_obj) + { + exp_to_add = exp; + limit = (levels[skill_obj->level + 1] - levels[skill_obj->level]) / 2; + if (exp_to_add > limit) + exp_to_add = limit; + + ADD_EXP (skill_obj->stats.exp, exp_to_add); + if (settings.permanent_exp_ratio) + { + skill_obj->perm_exp += + (sint64) ((float) exp_to_add * PERM_EXP_GAIN_RATIO); + calc_perm_exp (skill_obj); } - player_lvl_adj(op,skill_obj); + + player_lvl_adj (op, skill_obj); } }