Merge pull request #816 from ennorehling/master

Bug 2511: LERNE AUTO fixed, student limit increased
This commit is contained in:
Enno Rehling 2018-11-04 09:15:08 +01:00 committed by GitHub
commit 7a42f6926a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 27 deletions

View File

@ -28,33 +28,42 @@ static int cmp_scholars(const void *lhs, const void *rhs)
return (int)a->sk - (int)b->sk;
}
int autostudy_init(scholar scholars[], int max_scholars, region *r)
int autostudy_init(scholar scholars[], int max_scholars, unit **units)
{
unit *u;
unit *unext = NULL, *u = *units;
faction *f = u->faction;
int nscholars = 0;
for (u = r->units; u; u = u->next) {
while (u) {
keyword_t kwd = init_order(u->thisorder, u->faction->locale);
if (kwd == K_AUTOSTUDY) {
if (long_order_allowed(u)) {
scholar * st = scholars + nscholars;
skill_t sk = getskill(u->faction->locale);
if (check_student(u, u->thisorder, sk)) {
st->sk = sk;
st->level = effskill_study(u, st->sk);
st->learn = 0;
st->u = u;
if (++nscholars == max_scholars) {
log_fatal("you must increase MAXSCHOLARS");
if (f == u->faction) {
scholar * st = scholars + nscholars;
skill_t sk = getskill(u->faction->locale);
if (check_student(u, u->thisorder, sk)) {
st->sk = sk;
st->level = effskill_study(u, st->sk);
st->learn = 0;
st->u = u;
if (++nscholars == max_scholars) {
log_fatal("you must increase MAXSCHOLARS");
}
}
}
else if (!unext) {
unext = u;
}
}
else {
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "error_race_nolearn", "race",
u_race(u)));
}
}
u = u->next;
}
*units = unext;
scholars[nscholars].u = NULL;
if (nscholars > 0) {
qsort(scholars, nscholars, sizeof(scholar), cmp_scholars);
}
@ -149,15 +158,23 @@ void autostudy_run(scholar scholars[], int nscholars)
}
}
#define MAXSCHOLARS 128
#define MAXSCHOLARS 512
void do_autostudy(region *r)
{
static int max_scholars;
unit *units = r->units;
scholar scholars[MAXSCHOLARS];
int i, nscholars = autostudy_init(scholars, MAXSCHOLARS, r);
autostudy_run(scholars, nscholars);
for (i = 0; i != nscholars; ++i) {
int days = STUDYDAYS * scholars[i].learn;
learn_skill(scholars[i].u, scholars[i].sk, days);
while (units) {
int i, nscholars = autostudy_init(scholars, MAXSCHOLARS, &units);
if (nscholars > max_scholars) {
stats_count("automate.max_scholars", nscholars - max_scholars);
max_scholars = nscholars;
}
autostudy_run(scholars, nscholars);
for (i = 0; i != nscholars; ++i) {
int days = STUDYDAYS * scholars[i].learn;
learn_skill(scholars[i].u, scholars[i].sk, days);
}
}
}

View File

@ -37,7 +37,7 @@ typedef struct scholar {
void do_autostudy(struct region *r);
int autostudy_init(scholar scholars[], int max_scholars, struct region *r);
int autostudy_init(scholar scholars[], int max_scholars, struct unit **units);
void autostudy_run(scholar scholars[], int nscholars);
#endif

View File

@ -17,7 +17,7 @@
static void test_autostudy_init(CuTest *tc) {
scholar scholars[4];
unit *u1, *u2, *u3, *u4;
unit *u1, *u2, *u3, *u4, *u5, *ulist;
faction *f;
region *r;
@ -35,10 +35,13 @@ static void test_autostudy_init(CuTest *tc) {
set_level(u2, SK_ENTERTAINMENT, 2);
u3 = test_create_unit(f, r);
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
u4 = test_create_unit(test_create_faction(NULL), r);
u4 = test_create_unit(f, r);
u4->thisorder = create_order(K_AUTOSTUDY, f->locale, "Dudelidu");
u5 = test_create_unit(test_create_faction(NULL), r);
u5->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
scholars[3].u = NULL;
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, r));
ulist = r->units;
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, &ulist));
CuAssertPtrNotNull(tc, test_find_messagetype(u4->faction->msgs, "error77"));
CuAssertPtrEquals(tc, u2, scholars[0].u);
CuAssertIntEquals(tc, 2, scholars[0].level);
@ -53,12 +56,20 @@ static void test_autostudy_init(CuTest *tc) {
CuAssertIntEquals(tc, 0, scholars[2].learn);
CuAssertIntEquals(tc, SK_PERCEPTION, scholars[2].sk);
CuAssertPtrEquals(tc, NULL, scholars[3].u);
CuAssertPtrEquals(tc, u5, ulist);
CuAssertIntEquals(tc, 1, autostudy_init(scholars, 4, &ulist));
CuAssertPtrEquals(tc, u5, scholars[0].u);
CuAssertIntEquals(tc, 0, scholars[0].level);
CuAssertIntEquals(tc, 0, scholars[0].learn);
CuAssertIntEquals(tc, SK_PERCEPTION, scholars[0].sk);
CuAssertPtrEquals(tc, NULL, scholars[1].u);
CuAssertPtrEquals(tc, NULL, ulist);
test_teardown();
}
static void test_autostudy_run(CuTest *tc) {
scholar scholars[4];
unit *u1, *u2, *u3;
unit *u1, *u2, *u3, *ulist;
faction *f;
region *r;
@ -76,7 +87,9 @@ static void test_autostudy_run(CuTest *tc) {
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
set_number(u3, 15);
scholars[3].u = NULL;
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, r));
ulist = r->units;
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, &ulist));
CuAssertPtrEquals(tc, NULL, ulist);
autostudy_run(scholars, 3);
CuAssertIntEquals(tc, 0, scholars[0].learn);
CuAssertIntEquals(tc, 20, scholars[1].learn);
@ -86,7 +99,7 @@ static void test_autostudy_run(CuTest *tc) {
static void test_autostudy_run_noteachers(CuTest *tc) {
scholar scholars[4];
unit *u1, *u2, *u3;
unit *u1, *u2, *u3, *ulist;
faction *f;
region *r;
@ -104,7 +117,9 @@ static void test_autostudy_run_noteachers(CuTest *tc) {
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
set_number(u3, 15);
scholars[3].u = NULL;
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, r));
ulist = r->units;
CuAssertIntEquals(tc, 3, autostudy_init(scholars, 4, &ulist));
CuAssertPtrEquals(tc, NULL, ulist);
autostudy_run(scholars, 3);
CuAssertIntEquals(tc, 2, scholars[0].learn);
CuAssertIntEquals(tc, 10, scholars[1].learn);

View File

@ -26,7 +26,7 @@ extern "C" {
#endif
typedef struct skill {
skill_t id : 8;
int id : 8;
int level : 8;
int weeks : 8;
int old : 8;