forked from github/server
strip skillmod down to the essentials.
This commit is contained in:
parent
7dd79a1e79
commit
c6a8a76e31
|
@ -1 +1 @@
|
|||
Subproject commit ecf956b9808c28c2db52e6b73930f57876dbb258
|
||||
Subproject commit 22741d9ce9d19bf7b5f5a219b6ed0925259a4d1b
|
|
@ -62,8 +62,7 @@ attrib_type at_skillmod = {
|
|||
ATF_PRESERVE
|
||||
};
|
||||
|
||||
attrib *make_skillmod(skill_t sk, unsigned int flags, skillmod_fun special,
|
||||
double multiplier, int bonus)
|
||||
attrib *make_skillmod(skill_t sk, skillmod_fun special, double multiplier, int bonus)
|
||||
{
|
||||
attrib *a = a_new(&at_skillmod);
|
||||
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->bonus = bonus;
|
||||
smd->multiplier = multiplier;
|
||||
smd->flags = flags;
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
int
|
||||
skillmod(const attrib * a, const unit * u, const region * r, skill_t sk,
|
||||
int value, int flags)
|
||||
skillmod(const unit * u, const region * r, skill_t sk, int value)
|
||||
{
|
||||
const attrib * a = u->attribs;
|
||||
for (a = a_find((attrib *)a, &at_skillmod); a && a->type == &at_skillmod;
|
||||
a = a->next) {
|
||||
skillmod_data *smd = (skillmod_data *)a->data.v;
|
||||
if (smd->skill != NOSKILL && smd->skill != sk)
|
||||
continue;
|
||||
if (flags != SMF_ALWAYS && (smd->flags & flags) == 0)
|
||||
continue;
|
||||
if (smd->special) {
|
||||
value = smd->special(u, r, sk, value);
|
||||
if (value < 0)
|
||||
|
|
|
@ -25,10 +25,6 @@ struct attrib_type;
|
|||
extern "C" {
|
||||
#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 {
|
||||
skill_t id;
|
||||
int level;
|
||||
|
@ -44,17 +40,13 @@ extern "C" {
|
|||
double multiplier;
|
||||
int number;
|
||||
int bonus;
|
||||
int flags;
|
||||
} skillmod_data;
|
||||
|
||||
extern struct attrib_type at_skillmod;
|
||||
|
||||
int rc_skillmod(const struct race *rc, const struct region *r,
|
||||
skill_t sk);
|
||||
int skillmod(const struct attrib *a, const struct unit *u,
|
||||
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 rc_skillmod(const struct race *rc, const struct region *r, skill_t sk);
|
||||
int skillmod(const struct unit *u, const struct region *r, skill_t sk, int value);
|
||||
struct attrib *make_skillmod(skill_t sk, skillmod_fun special, double multiplier, int bonus);
|
||||
|
||||
int level_days(int level);
|
||||
int level(int days);
|
||||
|
|
|
@ -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 += att_modification(u, sk);
|
||||
|
||||
skill = skillmod(u->attribs, u, r, sk, skill, SMF_ALWAYS);
|
||||
if (u->attribs) {
|
||||
skill = skillmod(u, r, sk, skill);
|
||||
}
|
||||
|
||||
if (fval(u, UFL_HUNGER)) {
|
||||
if (sk == SK_SAILING && skill > 2) {
|
||||
|
|
|
@ -256,19 +256,19 @@ static void test_skillmod(CuTest *tc) {
|
|||
set_level(u, SK_ARMORER, 5);
|
||||
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));
|
||||
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));
|
||||
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));
|
||||
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));
|
||||
a_remove(&u->attribs, a);
|
||||
|
||||
|
|
|
@ -556,7 +556,7 @@ int sp_mindblast_temp(struct castorder * co)
|
|||
skill_t sk = random_skill(du, true);
|
||||
if (sk != NOSKILL) {
|
||||
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 */
|
||||
a_add(&du->attribs, a);
|
||||
}
|
||||
|
|
2
storage
2
storage
|
@ -1 +1 @@
|
|||
Subproject commit 2117191d4ad75e1eb14809878bc71d15b20a5d86
|
||||
Subproject commit d807ef5ce64b3425b31fb440e0b93a4d233f517a
|
Loading…
Reference in New Issue