forked from github/server
commit
b194ed39bd
|
@ -37,8 +37,13 @@ int u_geteffstealth(const unit *u)
|
|||
if (skill_enabled(SK_STEALTH)) {
|
||||
if (u->flags & UFL_STEALTH) {
|
||||
attrib *a = a_find(u->attribs, &at_stealth);
|
||||
if (a != NULL)
|
||||
if (a != NULL) {
|
||||
int eff = effskill(u, SK_STEALTH, u->region);
|
||||
if (eff < a->data.i) {
|
||||
return eff;
|
||||
}
|
||||
return a->data.i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
|
|
|
@ -20,7 +20,8 @@
|
|||
static int cmp_scholars(const void *lhs, const void *rhs) {
|
||||
const scholar *a = (const scholar *)lhs;
|
||||
const scholar *b = (const scholar *)rhs;
|
||||
return b->level - a->level;
|
||||
int diff = b->level - a->level;
|
||||
return (diff != 0) ? diff : b->u->number - a->u->number;
|
||||
}
|
||||
|
||||
int autostudy_init(scholar scholars[], int max_scholars, unit **units, skill_t *o_skill)
|
||||
|
@ -77,6 +78,7 @@ int autostudy_init(scholar scholars[], int max_scholars, unit **units, skill_t *
|
|||
|
||||
static void teaching(scholar *s, int n) {
|
||||
assert(n <= s->u->number);
|
||||
// doppelter Effekt mit Lehrer:
|
||||
s->learn += n;
|
||||
s->u->flags |= UFL_LONGACTION;
|
||||
}
|
||||
|
@ -91,27 +93,31 @@ void autostudy_run(scholar scholars[], int nscholars)
|
|||
{
|
||||
int ti = 0;
|
||||
while (ti != nscholars) {
|
||||
int t, se, ts = 0, tt = 0, si = ti;
|
||||
for (se = ti; se != nscholars; ++se) {
|
||||
int mint;
|
||||
ts += scholars[se].u->number; /* count total scholars */
|
||||
int t, ts = 0, tt = 0, si = ti, mint = 0, ns = 0;
|
||||
for (t = ti; t != nscholars; ++t) {
|
||||
ts += scholars[t].u->number; /* count total scholars */
|
||||
mint = (ts + 10) / 11; /* need a minimum of ceil(ts/11) teachers */
|
||||
for (; mint > tt && si != nscholars - 1; ++si) {
|
||||
for (; mint > tt && si != nscholars; ++si) {
|
||||
tt += scholars[si].u->number;
|
||||
}
|
||||
}
|
||||
if (mint < tt) {
|
||||
/* die Einheit si-1 hat einen Mix aus Lehrer und Schüler */
|
||||
--si;
|
||||
ns = tt - mint;
|
||||
}
|
||||
/* now si splits the teachers and students 1:10 */
|
||||
/* first student must be 2 levels below first teacher: */
|
||||
for (; si != se; ++si) {
|
||||
for (; si != nscholars; ++si) {
|
||||
if (scholars[si].level + TEACHDIFFERENCE <= scholars[ti].level) {
|
||||
break;
|
||||
}
|
||||
tt += scholars[si].u->number;
|
||||
ns = 0;
|
||||
}
|
||||
/* now si is the first unit we can teach, if we can teach any */
|
||||
if (si == se) {
|
||||
if (si == nscholars) {
|
||||
/* there are no students, so standard learning for everyone */
|
||||
for (t = ti; t != se; ++t) {
|
||||
for (t = ti; t != nscholars; ++t) {
|
||||
learning(scholars + t, scholars[t].u->number);
|
||||
}
|
||||
}
|
||||
|
@ -119,16 +125,17 @@ void autostudy_run(scholar scholars[], int nscholars)
|
|||
/* invariant: unit ti can still teach i students */
|
||||
int i = scholars[ti].u->number * STUDENTS_PER_TEACHER;
|
||||
/* invariant: unit si has n students that can still be taught */
|
||||
int s, n = scholars[si].u->number;
|
||||
for (t = ti, s = si; t != si && s != se; ) {
|
||||
int s, n = (ns > 0) ? ns : scholars[si].u->number;
|
||||
for (t = ti, s = si; t != si && s != nscholars; ) {
|
||||
if (i >= n) {
|
||||
/* t has more than enough teaching capacity for s */
|
||||
i -= n;
|
||||
teaching(scholars + s, n);
|
||||
learning(scholars + s, scholars[s].u->number);
|
||||
/* next student, please: */
|
||||
if (++s == se) {
|
||||
continue;
|
||||
if (++s == nscholars) {
|
||||
/* no more students */
|
||||
break;
|
||||
}
|
||||
n = scholars[s].u->number;
|
||||
}
|
||||
|
@ -147,7 +154,7 @@ void autostudy_run(scholar scholars[], int nscholars)
|
|||
do {
|
||||
/* remaining students learn without a teacher: */
|
||||
learning(scholars + s, n);
|
||||
if (++s == se) {
|
||||
if (++s == nscholars) {
|
||||
break;
|
||||
}
|
||||
n = scholars[s].u->number;
|
||||
|
@ -163,10 +170,15 @@ void autostudy_run(scholar scholars[], int nscholars)
|
|||
}
|
||||
++t;
|
||||
for (; t < si; ++t) {
|
||||
/* teachers that did not teach */
|
||||
learning(scholars + t, scholars[t].u->number);
|
||||
}
|
||||
for (; s < nscholars; ++s) {
|
||||
/* students that were not taught */
|
||||
learning(scholars + s, scholars[s].u->number);
|
||||
}
|
||||
}
|
||||
ti = se;
|
||||
ti = nscholars;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -139,7 +139,78 @@ static void test_autostudy_run_bigunit(CuTest *tc) {
|
|||
autostudy_run(scholars, nscholars);
|
||||
CuAssertIntEquals(tc, SK_ENTERTAINMENT, skill);
|
||||
CuAssertIntEquals(tc, 0, scholars[0].learn);
|
||||
CuAssertIntEquals(tc, 200, scholars[1].learn);
|
||||
CuAssertIntEquals(tc, 1200, scholars[1].learn);
|
||||
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
static void test_autostudy_run_few_teachers(CuTest *tc) {
|
||||
scholar scholars[4];
|
||||
int nscholars;
|
||||
unit *u1, *u2, *u3, *ulist;
|
||||
faction *f;
|
||||
region *r;
|
||||
skill_t skill;
|
||||
|
||||
test_setup();
|
||||
r = test_create_plain(0, 0);
|
||||
f = test_create_faction(NULL);
|
||||
u1 = test_create_unit(f, r);
|
||||
set_number(u1, 20);
|
||||
set_level(u1, SK_ENTERTAINMENT, 16);
|
||||
u1->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
|
||||
u2 = test_create_unit(f, r);
|
||||
set_number(u2, 500);
|
||||
set_level(u2, SK_ENTERTAINMENT, 10);
|
||||
u2->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
|
||||
u3 = test_create_unit(f, r);
|
||||
set_number(u3, 100);
|
||||
set_level(u3, SK_ENTERTAINMENT, 9);
|
||||
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
|
||||
|
||||
ulist = r->units;
|
||||
CuAssertIntEquals(tc, 3, nscholars = autostudy_init(scholars, 4, &ulist, &skill));
|
||||
CuAssertPtrEquals(tc, NULL, ulist);
|
||||
autostudy_run(scholars, nscholars);
|
||||
CuAssertIntEquals(tc, SK_ENTERTAINMENT, skill);
|
||||
CuAssertIntEquals(tc, 0, scholars[0].learn);
|
||||
CuAssertIntEquals(tc, 700, scholars[1].learn);
|
||||
CuAssertIntEquals(tc, 100, scholars[2].learn);
|
||||
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
static void test_autostudy_run_few_teachers_reverse(CuTest *tc) {
|
||||
scholar scholars[4];
|
||||
int nscholars;
|
||||
unit *u1, *u2, *u3, *ulist;
|
||||
faction *f;
|
||||
region *r;
|
||||
skill_t skill;
|
||||
|
||||
test_setup();
|
||||
r = test_create_plain(0, 0);
|
||||
f = test_create_faction(NULL);
|
||||
u1 = test_create_unit(f, r);
|
||||
set_number(u1, 20);
|
||||
set_level(u1, SK_ENTERTAINMENT, 16);
|
||||
u1->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
|
||||
u2 = test_create_unit(f, r);
|
||||
set_number(u2, 100);
|
||||
set_level(u2, SK_ENTERTAINMENT, 10);
|
||||
u2->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
|
||||
u3 = test_create_unit(f, r);
|
||||
set_number(u3, 500);
|
||||
set_level(u3, SK_ENTERTAINMENT, 9);
|
||||
u3->thisorder = create_order(K_AUTOSTUDY, f->locale, skillnames[SK_ENTERTAINMENT]);
|
||||
|
||||
ulist = r->units;
|
||||
CuAssertIntEquals(tc, 3, nscholars = autostudy_init(scholars, 4, &ulist, &skill));
|
||||
CuAssertPtrEquals(tc, NULL, ulist);
|
||||
autostudy_run(scholars, nscholars);
|
||||
CuAssertIntEquals(tc, SK_ENTERTAINMENT, skill);
|
||||
CuAssertIntEquals(tc, 0, scholars[0].learn);
|
||||
CuAssertIntEquals(tc, 800, scholars[1].learn + scholars[2].learn);
|
||||
|
||||
test_teardown();
|
||||
}
|
||||
|
@ -360,6 +431,8 @@ CuSuite *get_automate_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_autostudy_run_teachers_learn);
|
||||
SUITE_ADD_TEST(suite, test_autostudy_run_twoteachers);
|
||||
SUITE_ADD_TEST(suite, test_autostudy_run_bigunit);
|
||||
SUITE_ADD_TEST(suite, test_autostudy_run_few_teachers);
|
||||
SUITE_ADD_TEST(suite, test_autostudy_run_few_teachers_reverse);
|
||||
SUITE_ADD_TEST(suite, test_autostudy_run_skilldiff);
|
||||
return suite;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue