forked from github/server
bug: learn_skill was not learning the right skill
refactor: further reduce learn_skill_depr usage
This commit is contained in:
parent
0464fb629a
commit
f97b6c9821
|
@ -394,10 +394,10 @@ static int tolua_learn_skill(lua_State * L)
|
|||
{
|
||||
unit *u = (unit *)tolua_tousertype(L, 1, 0);
|
||||
const char *skname = tolua_tostring(L, 2, 0);
|
||||
float chances = (float)tolua_tonumber(L, 3, 0);
|
||||
int days = (int)tolua_tonumber(L, 3, 0);
|
||||
skill_t sk = findskill(skname);
|
||||
if (sk != NOSKILL) {
|
||||
learn_skill_depr(u, sk, chances);
|
||||
learn_skill(u, sk, days);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1119,7 +1119,7 @@ int tolua_bindings_open(lua_State * L)
|
|||
tolua_function(L, TOLUA_CAST "update_subscriptions", tolua_update_subscriptions);
|
||||
tolua_function(L, TOLUA_CAST "update_scores", tolua_update_scores);
|
||||
tolua_function(L, TOLUA_CAST "update_owners", tolua_update_owners);
|
||||
tolua_function(L, TOLUA_CAST "learn_skill_depr", tolua_learn_skill);
|
||||
tolua_function(L, TOLUA_CAST "learn_skill", tolua_learn_skill);
|
||||
tolua_function(L, TOLUA_CAST "create_curse", tolua_create_curse);
|
||||
tolua_function(L, TOLUA_CAST "autoseed", tolua_autoseed);
|
||||
tolua_function(L, TOLUA_CAST "get_key", tolua_getkey);
|
||||
|
|
|
@ -53,9 +53,7 @@ struct order *ord)
|
|||
for (n = 0; n != amount; ++n) {
|
||||
skill *sv = u->skills;
|
||||
while (sv != u->skills + u->skill_size) {
|
||||
int i;
|
||||
for (i = 0; i != 3; ++i)
|
||||
learn_skill_depr(u, (skill_t)sv->id, 1.0);
|
||||
learn_skill(u, (skill_t)sv->id, STUDYDAYS * 3);
|
||||
++sv;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,17 +31,17 @@ static void test_skillpotion(CuTest *tc) {
|
|||
itype = test_create_itemtype("skillpotion");
|
||||
change_resource(u, itype->rtype, 2);
|
||||
|
||||
learn_skill_depr(u, SK_ENTERTAINMENT, 1.0);
|
||||
learn_skill(u, SK_ENTERTAINMENT, STUDYDAYS);
|
||||
pSkill = unit_skill(u, SK_ENTERTAINMENT);
|
||||
sk_set(pSkill, 5);
|
||||
initialWeeks_Entertainment = pSkill->weeks = 4;
|
||||
|
||||
learn_skill_depr(u, SK_STAMINA, 1.0);
|
||||
learn_skill(u, SK_STAMINA, STUDYDAYS);
|
||||
pSkill = unit_skill(u, SK_STAMINA);
|
||||
sk_set(pSkill, 5);
|
||||
initialWeeks_Stamina = pSkill->weeks = 4;
|
||||
|
||||
learn_skill_depr(u, SK_MAGIC, 1.0);
|
||||
learn_skill(u, SK_MAGIC, STUDYDAYS);
|
||||
pSkill = unit_skill(u, SK_MAGIC);
|
||||
sk_set(pSkill, 5);
|
||||
initialWeeks_Magic = pSkill->weeks = 4;
|
||||
|
|
|
@ -206,7 +206,7 @@ int level(int days)
|
|||
|
||||
void sk_set(skill * sv, int level)
|
||||
{
|
||||
assert(level != 0);
|
||||
assert(sv && level != 0);
|
||||
sv->weeks = skill_weeks(level);
|
||||
sv->level = level;
|
||||
}
|
||||
|
|
|
@ -151,22 +151,17 @@ static void dissolve_units(void)
|
|||
remove_empty_units();
|
||||
}
|
||||
|
||||
static int improve_all(faction * f, skill_t sk, int by_weeks)
|
||||
static bool improve_all(faction * f, skill_t sk, int by_weeks)
|
||||
{
|
||||
unit *u;
|
||||
bool ret = by_weeks;
|
||||
|
||||
bool result = false;
|
||||
for (u = f->units; u; u = u->nextF) {
|
||||
if (has_skill(u, sk)) {
|
||||
int weeks = 0;
|
||||
for (; weeks != by_weeks; ++weeks) {
|
||||
learn_skill_depr(u, sk, 1.0);
|
||||
ret = 0;
|
||||
}
|
||||
learn_skill(u, sk, by_weeks * STUDYDAYS);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
return result;
|
||||
}
|
||||
|
||||
void find_manual(region * r, unit * u)
|
||||
|
@ -247,10 +242,8 @@ void find_manual(region * r, unit * u)
|
|||
msg_release(msg);
|
||||
}
|
||||
|
||||
if (improve_all(u->faction, skill, 3) == 3) {
|
||||
int i;
|
||||
for (i = 0; i != 9; ++i)
|
||||
learn_skill_depr(u, skill, 1.0);
|
||||
if (!improve_all(u->faction, skill, 3)) {
|
||||
learn_skill(u, skill, 9 * STUDYDAYS);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
18
src/study.c
18
src/study.c
|
@ -847,7 +847,6 @@ bool learn_skill_depr(unit * u, skill_t sk, double learn_chance)
|
|||
}
|
||||
|
||||
void learn_skill(unit *u, skill_t sk, int days) {
|
||||
skill *sv = u->skills;
|
||||
int leveldays = STUDYDAYS * u->number;
|
||||
int weeks = 0;
|
||||
while (days >= leveldays) {
|
||||
|
@ -857,14 +856,17 @@ void learn_skill(unit *u, skill_t sk, int days) {
|
|||
if (days > 0 && rng_int() % leveldays < days) {
|
||||
++weeks;
|
||||
}
|
||||
if (weeks > 0 && !sv) {
|
||||
sv = add_skill(u, sk);
|
||||
if (weeks > 0) {
|
||||
skill *sv = unit_skill(u, sk);
|
||||
if (!sv) {
|
||||
sv = add_skill(u, sk);
|
||||
}
|
||||
while (sv->weeks <= weeks) {
|
||||
weeks -= sv->weeks;
|
||||
sk_set(sv, sv->level + 1);
|
||||
}
|
||||
sv->weeks -= weeks;
|
||||
}
|
||||
while (sv->weeks <= weeks) {
|
||||
weeks -= sv->weeks;
|
||||
sk_set(sv, sv->level + 1);
|
||||
}
|
||||
sv->weeks -= weeks;
|
||||
}
|
||||
|
||||
/** Talente von Dämonen verschieben sich.
|
||||
|
|
Loading…
Reference in New Issue