forked from github/server
rewrite learn_skill to not use the deprecated function.
This commit is contained in:
parent
b5a4faa745
commit
af83efca44
33
src/study.c
33
src/study.c
|
@ -738,17 +738,7 @@ int study_cmd(unit * u, order * ord)
|
||||||
if (fval(u, UFL_HUNGER))
|
if (fval(u, UFL_HUNGER))
|
||||||
days /= 2;
|
days /= 2;
|
||||||
|
|
||||||
while (days) {
|
learn_skill(u, sk, days);
|
||||||
if (days >= u->number * 30) {
|
|
||||||
learn_skill_depr(u, sk, 1.0);
|
|
||||||
days -= u->number * 30;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
double chance = (double)days / u->number / 30;
|
|
||||||
learn_skill_depr(u, sk, chance);
|
|
||||||
days = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (a != NULL) {
|
if (a != NULL) {
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while (teach->teachers[index] && index != MAXTEACHERS) {
|
while (teach->teachers[index] && index != MAXTEACHERS) {
|
||||||
|
@ -857,10 +847,21 @@ bool learn_skill_depr(unit * u, skill_t sk, double learn_chance)
|
||||||
}
|
}
|
||||||
|
|
||||||
void learn_skill(unit *u, skill_t sk, int days) {
|
void learn_skill(unit *u, skill_t sk, int days) {
|
||||||
double ch = days*1.0 / STUDYDAYS;
|
skill *sv = u->skills;
|
||||||
while (ch >= 1.0) {
|
int weeks = 0;
|
||||||
learn_skill_depr(u, sk, 1.0);
|
while (days >= STUDYDAYS) {
|
||||||
ch -= 1.0;
|
++weeks;
|
||||||
|
days -= STUDYDAYS;
|
||||||
}
|
}
|
||||||
learn_skill_depr(u, sk, ch);
|
if (days > 0 && rng_int() % STUDYDAYS < days) {
|
||||||
|
++weeks;
|
||||||
|
}
|
||||||
|
if (weeks > 0 && !sv) {
|
||||||
|
sv = add_skill(u, sk);
|
||||||
|
}
|
||||||
|
while (sv->weeks <= weeks) {
|
||||||
|
weeks -= sv->weeks;
|
||||||
|
sk_set(sv, sv->level + 1);
|
||||||
|
}
|
||||||
|
sv->weeks -= weeks;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue