forked from github/server
Merge pull request #816 from ennorehling/master
Bug 2511: LERNE AUTO fixed, student limit increased
This commit is contained in:
commit
7a42f6926a
4 changed files with 59 additions and 27 deletions
|
@ -28,33 +28,42 @@ static int cmp_scholars(const void *lhs, const void *rhs)
|
||||||
return (int)a->sk - (int)b->sk;
|
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;
|
int nscholars = 0;
|
||||||
|
|
||||||
for (u = r->units; u; u = u->next) {
|
while (u) {
|
||||||
keyword_t kwd = init_order(u->thisorder, u->faction->locale);
|
keyword_t kwd = init_order(u->thisorder, u->faction->locale);
|
||||||
if (kwd == K_AUTOSTUDY) {
|
if (kwd == K_AUTOSTUDY) {
|
||||||
if (long_order_allowed(u)) {
|
if (long_order_allowed(u)) {
|
||||||
scholar * st = scholars + nscholars;
|
if (f == u->faction) {
|
||||||
skill_t sk = getskill(u->faction->locale);
|
scholar * st = scholars + nscholars;
|
||||||
if (check_student(u, u->thisorder, sk)) {
|
skill_t sk = getskill(u->faction->locale);
|
||||||
st->sk = sk;
|
if (check_student(u, u->thisorder, sk)) {
|
||||||
st->level = effskill_study(u, st->sk);
|
st->sk = sk;
|
||||||
st->learn = 0;
|
st->level = effskill_study(u, st->sk);
|
||||||
st->u = u;
|
st->learn = 0;
|
||||||
if (++nscholars == max_scholars) {
|
st->u = u;
|
||||||
log_fatal("you must increase MAXSCHOLARS");
|
if (++nscholars == max_scholars) {
|
||||||
|
log_fatal("you must increase MAXSCHOLARS");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!unext) {
|
||||||
|
unext = u;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "error_race_nolearn", "race",
|
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "error_race_nolearn", "race",
|
||||||
u_race(u)));
|
u_race(u)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
u = u->next;
|
||||||
}
|
}
|
||||||
|
*units = unext;
|
||||||
|
scholars[nscholars].u = NULL;
|
||||||
if (nscholars > 0) {
|
if (nscholars > 0) {
|
||||||
qsort(scholars, nscholars, sizeof(scholar), cmp_scholars);
|
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)
|
void do_autostudy(region *r)
|
||||||
{
|
{
|
||||||
|
static int max_scholars;
|
||||||
|
unit *units = r->units;
|
||||||
scholar scholars[MAXSCHOLARS];
|
scholar scholars[MAXSCHOLARS];
|
||||||
int i, nscholars = autostudy_init(scholars, MAXSCHOLARS, r);
|
while (units) {
|
||||||
autostudy_run(scholars, nscholars);
|
int i, nscholars = autostudy_init(scholars, MAXSCHOLARS, &units);
|
||||||
for (i = 0; i != nscholars; ++i) {
|
if (nscholars > max_scholars) {
|
||||||
int days = STUDYDAYS * scholars[i].learn;
|
stats_count("automate.max_scholars", nscholars - max_scholars);
|
||||||
learn_skill(scholars[i].u, scholars[i].sk, days);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ typedef struct scholar {
|
||||||
|
|
||||||
void do_autostudy(struct region *r);
|
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);
|
void autostudy_run(scholar scholars[], int nscholars);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
static void test_autostudy_init(CuTest *tc) {
|
static void test_autostudy_init(CuTest *tc) {
|
||||||
scholar scholars[4];
|
scholar scholars[4];
|
||||||
unit *u1, *u2, *u3, *u4;
|
unit *u1, *u2, *u3, *u4, *u5, *ulist;
|
||||||
faction *f;
|
faction *f;
|
||||||
region *r;
|
region *r;
|
||||||
|
|
||||||
|
@ -35,10 +35,13 @@ static void test_autostudy_init(CuTest *tc) {
|
||||||
set_level(u2, SK_ENTERTAINMENT, 2);
|
set_level(u2, SK_ENTERTAINMENT, 2);
|
||||||
u3 = test_create_unit(f, r);
|
u3 = test_create_unit(f, r);
|
||||||
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
|
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");
|
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;
|
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"));
|
CuAssertPtrNotNull(tc, test_find_messagetype(u4->faction->msgs, "error77"));
|
||||||
CuAssertPtrEquals(tc, u2, scholars[0].u);
|
CuAssertPtrEquals(tc, u2, scholars[0].u);
|
||||||
CuAssertIntEquals(tc, 2, scholars[0].level);
|
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, 0, scholars[2].learn);
|
||||||
CuAssertIntEquals(tc, SK_PERCEPTION, scholars[2].sk);
|
CuAssertIntEquals(tc, SK_PERCEPTION, scholars[2].sk);
|
||||||
CuAssertPtrEquals(tc, NULL, scholars[3].u);
|
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();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_autostudy_run(CuTest *tc) {
|
static void test_autostudy_run(CuTest *tc) {
|
||||||
scholar scholars[4];
|
scholar scholars[4];
|
||||||
unit *u1, *u2, *u3;
|
unit *u1, *u2, *u3, *ulist;
|
||||||
faction *f;
|
faction *f;
|
||||||
region *r;
|
region *r;
|
||||||
|
|
||||||
|
@ -76,7 +87,9 @@ static void test_autostudy_run(CuTest *tc) {
|
||||||
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
|
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
|
||||||
set_number(u3, 15);
|
set_number(u3, 15);
|
||||||
scholars[3].u = NULL;
|
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);
|
autostudy_run(scholars, 3);
|
||||||
CuAssertIntEquals(tc, 0, scholars[0].learn);
|
CuAssertIntEquals(tc, 0, scholars[0].learn);
|
||||||
CuAssertIntEquals(tc, 20, scholars[1].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) {
|
static void test_autostudy_run_noteachers(CuTest *tc) {
|
||||||
scholar scholars[4];
|
scholar scholars[4];
|
||||||
unit *u1, *u2, *u3;
|
unit *u1, *u2, *u3, *ulist;
|
||||||
faction *f;
|
faction *f;
|
||||||
region *r;
|
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]);
|
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_PERCEPTION]);
|
||||||
set_number(u3, 15);
|
set_number(u3, 15);
|
||||||
scholars[3].u = NULL;
|
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);
|
autostudy_run(scholars, 3);
|
||||||
CuAssertIntEquals(tc, 2, scholars[0].learn);
|
CuAssertIntEquals(tc, 2, scholars[0].learn);
|
||||||
CuAssertIntEquals(tc, 10, scholars[1].learn);
|
CuAssertIntEquals(tc, 10, scholars[1].learn);
|
||||||
|
|
|
@ -26,7 +26,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct skill {
|
typedef struct skill {
|
||||||
skill_t id : 8;
|
int id : 8;
|
||||||
int level : 8;
|
int level : 8;
|
||||||
int weeks : 8;
|
int weeks : 8;
|
||||||
int old : 8;
|
int old : 8;
|
||||||
|
|
Loading…
Reference in a new issue