forked from github/server
tricks to reduce sizeof(scholar)
This commit is contained in:
parent
c0113987db
commit
6e64d749b0
6 changed files with 21 additions and 19 deletions
|
@ -20,12 +20,12 @@ static int cmp_scholars(const void *lhs, const void *rhs)
|
|||
{
|
||||
const scholar *a = (const scholar *)lhs;
|
||||
const scholar *b = (const scholar *)rhs;
|
||||
if (a->sk == b->sk) {
|
||||
if (a->skill == b->skill) {
|
||||
/* sort by level, descending: */
|
||||
return b->level - a->level;
|
||||
}
|
||||
/* order by skill */
|
||||
return (int)a->sk - (int)b->sk;
|
||||
return a->skill - b->skill;
|
||||
}
|
||||
|
||||
int autostudy_init(scholar scholars[], int max_scholars, unit **units)
|
||||
|
@ -42,8 +42,8 @@ int autostudy_init(scholar scholars[], int max_scholars, unit **units)
|
|||
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->skill = (short)sk;
|
||||
st->level = (short)effskill_study(u, sk);
|
||||
st->learn = 0;
|
||||
st->u = u;
|
||||
if (++nscholars > max_scholars) {
|
||||
|
@ -81,26 +81,26 @@ void autostudy_run(scholar scholars[], int nscholars)
|
|||
{
|
||||
int ti = 0;
|
||||
while (ti != nscholars) {
|
||||
skill_t sk = scholars[ti].sk;
|
||||
int skill = scholars[ti].skill;
|
||||
int t, se, ts = 0, tt = 0, si = ti;
|
||||
for (se = ti; se != nscholars && scholars[se].sk == sk; ++se) {
|
||||
for (se = ti; se != nscholars && scholars[se].skill == skill; ++se) {
|
||||
int mint;
|
||||
ts += scholars[se].u->number; /* count total scholars */
|
||||
mint = (ts + 10) / 11; /* need a minimum of ceil(ts/11) teachers */
|
||||
for (; mint > tt && si != nscholars && scholars[si].sk == sk; ++si) {
|
||||
for (; mint > tt && si != nscholars && scholars[si].skill == skill; ++si) {
|
||||
tt += scholars[si].u->number;
|
||||
}
|
||||
}
|
||||
/* now si splits the teachers and students 1:10 */
|
||||
/* first student must be 2 levels below first teacher: */
|
||||
for (; si != se && scholars[si].sk == sk; ++si) {
|
||||
for (; si != se && scholars[si].skill == skill; ++si) {
|
||||
if (scholars[si].level + TEACHDIFFERENCE <= scholars[ti].level) {
|
||||
break;
|
||||
}
|
||||
tt += scholars[si].u->number;
|
||||
}
|
||||
/* now si is the first unit we can teach, if we can teach any */
|
||||
if (si == se || scholars[si].sk != sk) {
|
||||
if (si == se || scholars[si].skill != skill) {
|
||||
/* there are no students, so standard learning for everyone */
|
||||
for (t = ti; t != se; ++t) {
|
||||
learning(scholars + t, scholars[t].u->number);
|
||||
|
@ -177,7 +177,7 @@ void do_autostudy(region *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);
|
||||
learn_skill(scholars[i].u, (skill_t)scholars[i].skill, days);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ struct unit;
|
|||
|
||||
typedef struct scholar {
|
||||
struct unit *u;
|
||||
skill_t sk;
|
||||
int level;
|
||||
int learn;
|
||||
short skill;
|
||||
short level;
|
||||
} scholar;
|
||||
|
||||
#define STUDENTS_PER_TEACHER 10
|
||||
|
|
|
@ -46,22 +46,22 @@ static void test_autostudy_init(CuTest *tc) {
|
|||
CuAssertPtrEquals(tc, u2, scholars[0].u);
|
||||
CuAssertIntEquals(tc, 2, scholars[0].level);
|
||||
CuAssertIntEquals(tc, 0, scholars[0].learn);
|
||||
CuAssertIntEquals(tc, SK_ENTERTAINMENT, scholars[0].sk);
|
||||
CuAssertIntEquals(tc, SK_ENTERTAINMENT, scholars[0].skill);
|
||||
CuAssertPtrEquals(tc, u1, scholars[1].u);
|
||||
CuAssertIntEquals(tc, 0, scholars[1].level);
|
||||
CuAssertIntEquals(tc, 0, scholars[1].learn);
|
||||
CuAssertIntEquals(tc, SK_ENTERTAINMENT, scholars[1].sk);
|
||||
CuAssertIntEquals(tc, SK_ENTERTAINMENT, scholars[1].skill);
|
||||
CuAssertPtrEquals(tc, u3, scholars[2].u);
|
||||
CuAssertIntEquals(tc, 0, scholars[2].level);
|
||||
CuAssertIntEquals(tc, 0, scholars[2].learn);
|
||||
CuAssertIntEquals(tc, SK_PERCEPTION, scholars[2].sk);
|
||||
CuAssertIntEquals(tc, SK_PERCEPTION, scholars[2].skill);
|
||||
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);
|
||||
CuAssertIntEquals(tc, SK_PERCEPTION, scholars[0].skill);
|
||||
CuAssertPtrEquals(tc, NULL, ulist);
|
||||
test_teardown();
|
||||
}
|
||||
|
|
|
@ -300,7 +300,7 @@ unit *addplayer(region * r, faction * f)
|
|||
} while (rc == NULL || urc == RC_DAEMON || !playerrace(rc));
|
||||
u->irace = rc;
|
||||
}
|
||||
f->lastorders = 0;
|
||||
f->lastorders = turn;
|
||||
return u;
|
||||
}
|
||||
|
||||
|
|
|
@ -344,6 +344,7 @@ static void test_addplayer(CuTest *tc) {
|
|||
CuAssertPtrNotNull(tc, u);
|
||||
CuAssertPtrEquals(tc, r, u->region);
|
||||
CuAssertPtrEquals(tc, f, u->faction);
|
||||
CuAssertIntEquals(tc, turn, u->faction->lastorders);
|
||||
CuAssertIntEquals(tc, i_get(u->items, itype), 10);
|
||||
CuAssertPtrNotNull(tc, u->orders);
|
||||
CuAssertIntEquals(tc, K_WORK, getkeyword(u->orders));
|
||||
|
|
|
@ -860,8 +860,9 @@ void reduce_skill_days(unit *u, skill_t sk, int days) {
|
|||
}
|
||||
}
|
||||
|
||||
/** Talente von Daemonen verschieben sich.
|
||||
*/
|
||||
/**
|
||||
* Talente von Daemonen verschieben sich.
|
||||
*/
|
||||
void demon_skillchange(unit *u)
|
||||
{
|
||||
skill *sv = u->skills;
|
||||
|
|
Loading…
Reference in a new issue