strip skillmod down to the essentials.

This commit is contained in:
Enno Rehling 2017-04-02 20:17:39 +02:00
parent 7dd79a1e79
commit c6a8a76e31
7 changed files with 16 additions and 27 deletions

@ -1 +1 @@
Subproject commit ecf956b9808c28c2db52e6b73930f57876dbb258 Subproject commit 22741d9ce9d19bf7b5f5a219b6ed0925259a4d1b

View File

@ -62,8 +62,7 @@ attrib_type at_skillmod = {
ATF_PRESERVE ATF_PRESERVE
}; };
attrib *make_skillmod(skill_t sk, unsigned int flags, skillmod_fun special, attrib *make_skillmod(skill_t sk, skillmod_fun special, double multiplier, int bonus)
double multiplier, int bonus)
{ {
attrib *a = a_new(&at_skillmod); attrib *a = a_new(&at_skillmod);
skillmod_data *smd = (skillmod_data *)a->data.v; skillmod_data *smd = (skillmod_data *)a->data.v;
@ -72,22 +71,19 @@ attrib *make_skillmod(skill_t sk, unsigned int flags, skillmod_fun special,
smd->special = special; smd->special = special;
smd->bonus = bonus; smd->bonus = bonus;
smd->multiplier = multiplier; smd->multiplier = multiplier;
smd->flags = flags;
return a; return a;
} }
int int
skillmod(const attrib * a, const unit * u, const region * r, skill_t sk, skillmod(const unit * u, const region * r, skill_t sk, int value)
int value, int flags)
{ {
const attrib * a = u->attribs;
for (a = a_find((attrib *)a, &at_skillmod); a && a->type == &at_skillmod; for (a = a_find((attrib *)a, &at_skillmod); a && a->type == &at_skillmod;
a = a->next) { a = a->next) {
skillmod_data *smd = (skillmod_data *)a->data.v; skillmod_data *smd = (skillmod_data *)a->data.v;
if (smd->skill != NOSKILL && smd->skill != sk) if (smd->skill != NOSKILL && smd->skill != sk)
continue; continue;
if (flags != SMF_ALWAYS && (smd->flags & flags) == 0)
continue;
if (smd->special) { if (smd->special) {
value = smd->special(u, r, sk, value); value = smd->special(u, r, sk, value);
if (value < 0) if (value < 0)

View File

@ -25,10 +25,6 @@ struct attrib_type;
extern "C" { extern "C" {
#endif #endif
/* skillmod_data::flags -- wann gilt der modifier? */
#define SMF_ALWAYS (1<<0) /* immer */
#define SMF_PRODUCTION (1<<1) /* für Produktion - am gebäude, an der einheit */
typedef struct skill { typedef struct skill {
skill_t id; skill_t id;
int level; int level;
@ -44,17 +40,13 @@ extern "C" {
double multiplier; double multiplier;
int number; int number;
int bonus; int bonus;
int flags;
} skillmod_data; } skillmod_data;
extern struct attrib_type at_skillmod; extern struct attrib_type at_skillmod;
int rc_skillmod(const struct race *rc, const struct region *r, int rc_skillmod(const struct race *rc, const struct region *r, skill_t sk);
skill_t sk); int skillmod(const struct unit *u, const struct region *r, skill_t sk, int value);
int skillmod(const struct attrib *a, const struct unit *u, struct attrib *make_skillmod(skill_t sk, skillmod_fun special, double multiplier, int bonus);
const struct region *r, skill_t sk, int value, int flags);
struct attrib *make_skillmod(skill_t sk, unsigned int flags,
skillmod_fun special, double multiplier, int bonus);
int level_days(int level); int level_days(int level);
int level(int days); int level(int days);

View File

@ -1333,8 +1333,9 @@ int get_modifier(const unit * u, skill_t sk, int level, const region * r, bool n
skill += rc_skillmod(u_race(u), r, sk); skill += rc_skillmod(u_race(u), r, sk);
skill += att_modification(u, sk); skill += att_modification(u, sk);
if (u->attribs) {
skill = skillmod(u->attribs, u, r, sk, skill, SMF_ALWAYS); skill = skillmod(u, r, sk, skill);
}
if (fval(u, UFL_HUNGER)) { if (fval(u, UFL_HUNGER)) {
if (sk == SK_SAILING && skill > 2) { if (sk == SK_SAILING && skill > 2) {

View File

@ -256,19 +256,19 @@ static void test_skillmod(CuTest *tc) {
set_level(u, SK_ARMORER, 5); set_level(u, SK_ARMORER, 5);
CuAssertIntEquals(tc, 5, effskill(u, SK_ARMORER, 0)); CuAssertIntEquals(tc, 5, effskill(u, SK_ARMORER, 0));
a_add(&u->attribs, a = make_skillmod(SK_ARMORER, SMF_ALWAYS, 0, 2.0, 0)); a_add(&u->attribs, a = make_skillmod(SK_ARMORER, 0, 2.0, 0));
CuAssertIntEquals(tc, 10, effskill(u, SK_ARMORER, 0)); CuAssertIntEquals(tc, 10, effskill(u, SK_ARMORER, 0));
a_remove(&u->attribs, a); a_remove(&u->attribs, a);
a_add(&u->attribs, a = make_skillmod(NOSKILL, SMF_ALWAYS, 0, 2.0, 0)); /* NOSKILL means any skill */ a_add(&u->attribs, a = make_skillmod(NOSKILL, 0, 2.0, 0)); /* NOSKILL means any skill */
CuAssertIntEquals(tc, 10, effskill(u, SK_ARMORER, 0)); CuAssertIntEquals(tc, 10, effskill(u, SK_ARMORER, 0));
a_remove(&u->attribs, a); a_remove(&u->attribs, a);
a_add(&u->attribs, a = make_skillmod(SK_ARMORER, SMF_ALWAYS, 0, 0, 2)); a_add(&u->attribs, a = make_skillmod(SK_ARMORER, 0, 0, 2));
CuAssertIntEquals(tc, 7, effskill(u, SK_ARMORER, 0)); CuAssertIntEquals(tc, 7, effskill(u, SK_ARMORER, 0));
a_remove(&u->attribs, a); a_remove(&u->attribs, a);
a_add(&u->attribs, a = make_skillmod(SK_ARMORER, SMF_ALWAYS, cb_skillmod, 0, 0)); a_add(&u->attribs, a = make_skillmod(SK_ARMORER, cb_skillmod, 0, 0));
CuAssertIntEquals(tc, 8, effskill(u, SK_ARMORER, 0)); CuAssertIntEquals(tc, 8, effskill(u, SK_ARMORER, 0));
a_remove(&u->attribs, a); a_remove(&u->attribs, a);

View File

@ -556,7 +556,7 @@ int sp_mindblast_temp(struct castorder * co)
skill_t sk = random_skill(du, true); skill_t sk = random_skill(du, true);
if (sk != NOSKILL) { if (sk != NOSKILL) {
int n = 1 + rng_int() % maxloss; int n = 1 + rng_int() % maxloss;
attrib *a = make_skillmod(sk, SMF_ALWAYS, NULL, 0.0, n); attrib *a = make_skillmod(sk, NULL, 0.0, n);
/* neat: you can add a whole lot of these to a unit, they stack */ /* neat: you can add a whole lot of these to a unit, they stack */
a_add(&du->attribs, a); a_add(&du->attribs, a);
} }

@ -1 +1 @@
Subproject commit 2117191d4ad75e1eb14809878bc71d15b20a5d86 Subproject commit d807ef5ce64b3425b31fb440e0b93a4d233f517a