forked from github/server
more skill size savings.
This commit is contained in:
parent
5cdd79804a
commit
f1be8caa46
5 changed files with 25 additions and 9 deletions
|
@ -324,20 +324,29 @@ static void writeorder(gamedata *data, const struct order *ord,
|
|||
static void read_skill(gamedata *data, skill *sv) {
|
||||
int val;
|
||||
READ_INT(data->store, &val);
|
||||
assert(val < MAXSKILLS);
|
||||
sv->id = (skill_t)val;
|
||||
if (sv->id != NOSKILL) {
|
||||
READ_INT(data->store, &val);
|
||||
assert(val < CHAR_MAX);
|
||||
sv->old = sv->level = val;
|
||||
READ_INT(data->store, &val);
|
||||
assert(val < CHAR_MAX);
|
||||
sv->weeks = val;
|
||||
}
|
||||
}
|
||||
|
||||
static int skill_cmp(const void *a, const void *b) {
|
||||
const skill * sa = (const skill *)a;
|
||||
const skill * sb = (const skill *)b;
|
||||
return sa->id - sb->id;
|
||||
}
|
||||
|
||||
static void read_skills(gamedata *data, unit *u)
|
||||
{
|
||||
if (data->version < SKILLSORT_VERSION) {
|
||||
skill skills[MAXSKILLS], *sv = skills;
|
||||
size_t sz;
|
||||
|
||||
u->skill_size = 0;
|
||||
for (;;) {
|
||||
read_skill(data, sv);
|
||||
|
@ -347,9 +356,13 @@ static void read_skills(gamedata *data, unit *u)
|
|||
++u->skill_size;
|
||||
}
|
||||
}
|
||||
sz = u->skill_size * sizeof(skill);
|
||||
u->skills = malloc(sz);
|
||||
memcpy(u->skills, skills, sz);
|
||||
if (u->skill_size > 0) {
|
||||
size_t sz = u->skill_size * sizeof(skill);
|
||||
|
||||
qsort(skills, u->skill_size, sizeof(skill), skill_cmp);
|
||||
u->skills = malloc(sz);
|
||||
memcpy(u->skills, skills, sz);
|
||||
}
|
||||
}
|
||||
else {
|
||||
int i;
|
||||
|
|
|
@ -619,7 +619,8 @@ static void test_shipspeed_max_range(CuTest *tc) {
|
|||
CuAssertIntEquals_Msg(tc, "skill bonus from movement.shipspeed.skillbonus", 3, shipspeed(sh, cap));
|
||||
|
||||
set_level(cap, SK_SAILING, stype->cptskill + 15);
|
||||
set_level(crew, SK_SAILING, (stype->sumskill - stype->cptskill) * 15);
|
||||
scale_number(crew, 15);
|
||||
set_level(crew, SK_SAILING, stype->sumskill - stype->cptskill);
|
||||
CuAssertIntEquals_Msg(tc, "skill-bonus cannot exceed max_range", 4, shipspeed(sh, cap));
|
||||
test_teardown();
|
||||
}
|
||||
|
|
|
@ -26,10 +26,10 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
typedef struct skill {
|
||||
skill_t id : 16;
|
||||
int level : 16;
|
||||
int weeks : 16;
|
||||
int old : 16;
|
||||
skill_t id : 8;
|
||||
int level : 8;
|
||||
int weeks : 8;
|
||||
int old : 8;
|
||||
} skill;
|
||||
|
||||
typedef int(*skillmod_fun) (const struct unit *, const struct region *,
|
||||
|
|
|
@ -795,6 +795,7 @@ void set_level(unit * u, skill_t sk, int value)
|
|||
skill *sv = u->skills;
|
||||
|
||||
assert(sk != SK_MAGIC || !u->faction || u->number == 1 || fval(u->faction, FFL_NPC));
|
||||
assert(value <= CHAR_MAX && value >= CHAR_MIN);
|
||||
if (!skill_enabled(sk))
|
||||
return;
|
||||
|
||||
|
|
|
@ -828,6 +828,7 @@ void learn_skill(unit *u, skill_t sk, int days) {
|
|||
int leveldays = STUDYDAYS * u->number;
|
||||
int weeks = 0;
|
||||
|
||||
assert(sk >= 0 && sk < MAXSKILLS);
|
||||
if (inject_learn_fun) {
|
||||
inject_learn_fun(u, sk, days);
|
||||
return;
|
||||
|
|
Loading…
Reference in a new issue