fixed demon_skillchange and produceexp

learn_skill's argument is the number of person days, not the number of unit days as assumed!
This commit is contained in:
Steffen Mecke 2017-08-04 15:17:18 +02:00
parent 80bfb5dbc6
commit f0c17b01af
5 changed files with 18 additions and 15 deletions

View File

@ -25,9 +25,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "academy.h" #include "academy.h"
#include "study.h" #include "study.h"
void academy_teaching_bonus(struct unit *u, skill_t sk, int academy) { void academy_teaching_bonus(struct unit *u, skill_t sk, int student_days) {
if (academy && sk != NOSKILL) { if (student_days && sk != NOSKILL) {
learn_skill(u, sk, academy); /* actually days / STUDYDAYS * EXPERIENCEDAYS / MAX_STUDENTS */
learn_skill(u, sk, student_days / STUDYDAYS);
} }
} }

View File

@ -54,6 +54,7 @@ struct order *ord)
for (n = 0; n != amount; ++n) { for (n = 0; n != amount; ++n) {
skill *sv = u->skills; skill *sv = u->skills;
while (sv != u->skills + u->skill_size) { while (sv != u->skills + u->skill_size) {
/* only one person learns for 3 weeks */
learn_skill(u, (skill_t)sv->id, STUDYDAYS * 3); learn_skill(u, (skill_t)sv->id, STUDYDAYS * 3);
++sv; ++sv;
} }

View File

@ -31,17 +31,17 @@ static void test_skillpotion(CuTest *tc) {
itype = test_create_itemtype("skillpotion"); itype = test_create_itemtype("skillpotion");
change_resource(u, itype->rtype, 2); change_resource(u, itype->rtype, 2);
learn_skill(u, SK_ENTERTAINMENT, STUDYDAYS); learn_skill(u, SK_ENTERTAINMENT, STUDYDAYS * u->number);
pSkill = unit_skill(u, SK_ENTERTAINMENT); pSkill = unit_skill(u, SK_ENTERTAINMENT);
sk_set(pSkill, 5); sk_set(pSkill, 5);
initialWeeks_Entertainment = pSkill->weeks = 4; initialWeeks_Entertainment = pSkill->weeks = 4;
learn_skill(u, SK_STAMINA, STUDYDAYS); learn_skill(u, SK_STAMINA, STUDYDAYS * u->number);
pSkill = unit_skill(u, SK_STAMINA); pSkill = unit_skill(u, SK_STAMINA);
sk_set(pSkill, 5); sk_set(pSkill, 5);
initialWeeks_Stamina = pSkill->weeks = 4; initialWeeks_Stamina = pSkill->weeks = 4;
learn_skill(u, SK_MAGIC, STUDYDAYS); learn_skill(u, SK_MAGIC, STUDYDAYS * u->number);
pSkill = unit_skill(u, SK_MAGIC); pSkill = unit_skill(u, SK_MAGIC);
sk_set(pSkill, 5); sk_set(pSkill, 5);
initialWeeks_Magic = pSkill->weeks = 4; initialWeeks_Magic = pSkill->weeks = 4;

View File

@ -484,7 +484,7 @@ int teach_cmd(unit * teacher, struct order *ord)
} }
if (academy && sk_academy!=NOSKILL) { if (academy && sk_academy!=NOSKILL) {
assert(academy % STUDYDAYS == 0); assert(academy % STUDYDAYS == 0);
academy_teaching_bonus(teacher, sk_academy, academy / STUDYDAYS); academy_teaching_bonus(teacher, sk_academy, academy);
} }
return 0; return 0;
} }
@ -842,7 +842,7 @@ void produceexp_ex(struct unit *u, skill_t sk, int n, learn_fun learn)
assert(u && n <= u->number); assert(u && n <= u->number);
if (n > 0 && (is_monsters(u->faction) || playerrace(u_race(u)))) { if (n > 0 && (is_monsters(u->faction) || playerrace(u_race(u)))) {
int days = produceexp_days(); int days = produceexp_days();
learn(u, sk, days * n / u->number); learn(u, sk, days * n);
} }
} }
@ -858,6 +858,7 @@ void inject_learn(learn_fun fun) {
inject_learn_fun = fun; inject_learn_fun = fun;
} }
#endif #endif
/** days should be scaled by u->number; STUDYDAYS * u->number is one week worth of learning */
void learn_skill(unit *u, skill_t sk, int days) { void learn_skill(unit *u, skill_t sk, int days) {
int leveldays = STUDYDAYS * u->number; int leveldays = STUDYDAYS * u->number;
int weeks = 0; int weeks = 0;
@ -929,7 +930,7 @@ void demon_skillchange(unit *u)
} }
} }
else { else {
learn_skill(u, sv->id, STUDYDAYS*weeks); learn_skill(u, sv->id, STUDYDAYS * u->number * weeks);
} }
} }
++sv; ++sv;

View File

@ -184,12 +184,12 @@ static CuTest *g_tc;
static void cb_learn_one(unit *u, skill_t sk, int days) { static void cb_learn_one(unit *u, skill_t sk, int days) {
CuAssertIntEquals(g_tc, SK_ALCHEMY, sk); CuAssertIntEquals(g_tc, SK_ALCHEMY, sk);
CuAssertIntEquals(g_tc, 10, days); CuAssertIntEquals(g_tc, 20, days);
} }
static void cb_learn_two(unit *u, skill_t sk, int days) { static void cb_learn_two(unit *u, skill_t sk, int days) {
CuAssertIntEquals(g_tc, SK_ALCHEMY, sk); CuAssertIntEquals(g_tc, SK_ALCHEMY, sk);
CuAssertIntEquals(g_tc, 20, days); CuAssertIntEquals(g_tc, 40, days);
} }
static void test_produceexp(CuTest *tc) { static void test_produceexp(CuTest *tc) {
@ -247,7 +247,7 @@ static void test_academy_building(CuTest *tc) {
CuAssertPtrEquals(tc, u, log_learners[0].u); CuAssertPtrEquals(tc, u, log_learners[0].u);
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk); CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk);
CuAssertIntEquals(tc, 15, log_learners[0].days); CuAssertIntEquals(tc, u1->number, log_learners[0].days);
test_cleanup(); test_cleanup();
} }
@ -377,7 +377,7 @@ static void test_study_cost(CuTest *tc) {
learn_reset(); learn_reset();
CuAssertPtrEquals(tc, u, log_learners[0].u); CuAssertPtrEquals(tc, u, log_learners[0].u);
CuAssertIntEquals(tc, SK_ALCHEMY, log_learners[0].sk); CuAssertIntEquals(tc, SK_ALCHEMY, log_learners[0].sk);
CuAssertIntEquals(tc, STUDYDAYS*u->number, log_learners[0].days); CuAssertIntEquals(tc, STUDYDAYS * u->number, log_learners[0].days);
CuAssertIntEquals(tc, 0, i_get(u->items, itype)); CuAssertIntEquals(tc, 0, i_get(u->items, itype));
test_cleanup(); test_cleanup();
} }
@ -405,7 +405,7 @@ static void test_teach_magic(CuTest *tc) {
learn_reset(); learn_reset();
CuAssertPtrEquals(tc, u, log_learners[0].u); CuAssertPtrEquals(tc, u, log_learners[0].u);
CuAssertIntEquals(tc, SK_MAGIC, log_learners[0].sk); CuAssertIntEquals(tc, SK_MAGIC, log_learners[0].sk);
CuAssertIntEquals(tc, STUDYDAYS*2, log_learners[0].days); CuAssertIntEquals(tc, STUDYDAYS * 2, log_learners[0].days);
CuAssertIntEquals(tc, 0, i_get(u->items, itype)); CuAssertIntEquals(tc, 0, i_get(u->items, itype));
test_cleanup(); test_cleanup();
} }
@ -426,7 +426,7 @@ static void test_teach_cmd(CuTest *tc) {
learn_reset(); learn_reset();
CuAssertPtrEquals(tc, u, log_learners[0].u); CuAssertPtrEquals(tc, u, log_learners[0].u);
CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk); CuAssertIntEquals(tc, SK_CROSSBOW, log_learners[0].sk);
CuAssertIntEquals(tc, STUDYDAYS*2*u->number, log_learners[0].days); CuAssertIntEquals(tc, STUDYDAYS * 2 * u->number, log_learners[0].days);
test_cleanup(); test_cleanup();
} }