diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5dbf70fa3..064728317 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,6 +60,7 @@ set (ERESSEA_SRC eressea.c direction.c keyword.c + skill.c json.c creation.c creport.c @@ -146,6 +147,7 @@ set(TESTS_SRC tests.test.c direction.test.c keyword.test.c + skill.test.c json.test.c economy.test.c market.test.c diff --git a/src/bind_unit.c b/src/bind_unit.c index cccb045ab..4886408da 100755 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -39,7 +39,6 @@ without prior permission by the authors of Eressea. #include #include #include -#include #include #include @@ -393,10 +392,10 @@ static int tolua_unit_getskill(lua_State * L) { unit *self = (unit *) tolua_tousertype(L, 1, 0); const char *skname = tolua_tostring(L, 2, 0); - skill_t sk = sk_find(skname); + skill_t sk = findskill(skname); int value = -1; if (sk != NOSKILL) { - skill *sv = get_skill(self, sk); + skill *sv = unit_skill(self, sk); if (sv) { value = sv->level; } else @@ -410,7 +409,7 @@ static int tolua_unit_effskill(lua_State * L) { unit *self = (unit *) tolua_tousertype(L, 1, 0); const char *skname = tolua_tostring(L, 2, 0); - skill_t sk = sk_find(skname); + skill_t sk = findskill(skname); int value = (sk == NOSKILL) ? -1 : eff_skill(self, sk, self->region); lua_pushinteger(L, value); return 1; @@ -572,7 +571,7 @@ static int tolua_unit_setskill(lua_State * L) unit *self = (unit *) tolua_tousertype(L, 1, 0); const char *skname = tolua_tostring(L, 2, 0); int level = (int)tolua_tonumber(L, 3, 0); - skill_t sk = sk_find(skname); + skill_t sk = findskill(skname); if (sk != NOSKILL) { set_level(self, sk, level); } else { diff --git a/src/bindings.c b/src/bindings.c index 53eba387f..fa7ee8a76 100755 --- a/src/bindings.c +++ b/src/bindings.c @@ -30,7 +30,6 @@ without prior permission by the authors of Eressea. #include #include #include -#include #include #include #include @@ -376,7 +375,7 @@ static int tolua_learn_skill(lua_State * L) unit *u = (unit *) tolua_tousertype(L, 1, 0); const char *skname = tolua_tostring(L, 2, 0); float chances = (float)tolua_tonumber(L, 3, 0); - skill_t sk = sk_find(skname); + skill_t sk = findskill(skname); if (sk != NOSKILL) { learn_skill(u, sk, chances); } diff --git a/src/creport.c b/src/creport.c index 3b2767197..27eda1de3 100644 --- a/src/creport.c +++ b/src/creport.c @@ -50,7 +50,6 @@ without prior permission by the authors of Eressea. #include #include #include -#include #include #include #include @@ -827,7 +826,7 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f, fprintf(F, "\"%s\";Typ\n", translate(zRace, locale_string(f->locale, zRace))); if (u->faction == f && irace != u_race(u)) { - assert(skill_enabled[SK_STEALTH] + assert(skill_enabled(SK_STEALTH) || !"we're resetting this on load, so.. ircase should never be used"); zRace = rc_name(u_race(u), 1); fprintf(F, "\"%s\";wahrerTyp\n", @@ -1298,7 +1297,7 @@ static void cr_output_region(FILE * F, report_context * ctx, seen_region * sr) } } fprintf(F, "%d;Silber\n", rmoney(r)); - if (skill_enabled[SK_ENTERTAINMENT]) { + if (skill_enabled(SK_ENTERTAINMENT)) { fprintf(F, "%d;Unterh\n", entertainmoney(r)); } if (is_cursed(r->attribs, C_RIOT, 0)) { diff --git a/src/economy.c b/src/economy.c index 241788c92..342f6d15c 100644 --- a/src/economy.c +++ b/src/economy.c @@ -46,7 +46,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include @@ -192,7 +191,7 @@ static void expandorders(region * r, request * requests) static void change_level(unit * u, skill_t sk, int bylevel) { - skill *sv = get_skill(u, sk); + skill *sv = unit_skill(u, sk); assert(bylevel > 0); if (sv == 0) sv = add_skill(u, sk); @@ -968,7 +967,7 @@ static int forget_cmd(unit * u, order * ord) skip_token(); s = getstrtoken(); - if ((sk = findskill(s, u->faction->locale)) != NOSKILL) { + if ((sk = get_skill(s, u->faction->locale)) != NOSKILL) { ADDMSG(&u->faction->msgs, msg_message("forget", "unit skill", u, sk)); set_level(u, sk, 0); } @@ -2762,7 +2761,7 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders) faction *f = NULL; plane *pl; - assert(skill_enabled[SK_PERCEPTION] && skill_enabled[SK_STEALTH]); + assert(skill_enabled(SK_PERCEPTION) && skill_enabled(SK_STEALTH)); if (!fval(u_race(u), RCF_CANSTEAL)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nosteal", "race", diff --git a/src/give.c b/src/give.c index d700b10f4..1124c2dd8 100644 --- a/src/give.c +++ b/src/give.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include diff --git a/src/items.c b/src/items.c index f8718b657..2a4c81568 100644 --- a/src/items.c +++ b/src/items.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -41,8 +40,8 @@ use_studypotion(struct unit *u, const struct item_type *itype, int amount, init_tokens(u->thisorder); skip_token(); - sk = findskill(getstrtoken(), u->faction->locale); - sv = get_skill(u, sk); + sk = get_skill(getstrtoken(), u->faction->locale); + sv = unit_skill(u, sk); if (sv && sv->level > 2) { /* TODO: message */ diff --git a/src/items/artrewards.c b/src/items/artrewards.c index 808f289f8..9226bb301 100644 --- a/src/items/artrewards.c +++ b/src/items/artrewards.c @@ -27,7 +27,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/items/xerewards.c b/src/items/xerewards.c index a22de46be..8b7978073 100644 --- a/src/items/xerewards.c +++ b/src/items/xerewards.c @@ -25,7 +25,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 707cbf63d..a10dbf21b 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -49,7 +49,7 @@ reports.c resources.c save.c ship.c -skill.c +skills.c spellbook.c spell.c teleport.c diff --git a/src/kernel/battle.c b/src/kernel/battle.c index c98dab9df..3e1235231 100644 --- a/src/kernel/battle.c +++ b/src/kernel/battle.c @@ -980,7 +980,7 @@ void drain_exp(struct unit *u, int n) } } if (sk != NOSKILL) { - skill *sv = get_skill(u, sk); + skill *sv = unit_skill(u, sk); while (n > 0) { if (n >= 30 * u->number) { reduce_skill(u, sv, 1); diff --git a/src/kernel/battle.test.c b/src/kernel/battle.test.c index f20fc51bc..cd57eb147 100644 --- a/src/kernel/battle.test.c +++ b/src/kernel/battle.test.c @@ -26,8 +26,8 @@ static void test_make_fighter(CuTest * tc) r = findregion(0, 0); f = test_create_faction(rc_find("human")); au = test_create_unit(f, r); - skill_enabled[SK_MAGIC] = 1; - skill_enabled[SK_RIDING] = 1; + enable_skill(SK_MAGIC, true); + enable_skill(SK_RIDING, true); set_level(au, SK_MAGIC, 3); set_level(au, SK_RIDING, 3); au->status = ST_BEHIND; diff --git a/src/kernel/build.h b/src/kernel/build.h index 3f469e665..a4afb5d81 100644 --- a/src/kernel/build.h +++ b/src/kernel/build.h @@ -21,6 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "types.h" #include "direction.h" +#include "skill.h" #ifdef __cplusplus extern "C" { diff --git a/src/kernel/config.c b/src/kernel/config.c index 99796d907..a92386433 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -416,29 +416,6 @@ const char *options[MAXOPTIONS] = { "SHOWSKCHANGE" }; -static int allied_skillcount(const faction * f, skill_t sk) -{ - int num = 0; - alliance *a = f_get_alliance(f); - quicklist *members = a->members; - int qi; - - for (qi = 0; members; ql_advance(&members, &qi, 1)) { - faction *m = (faction *) ql_get(members, qi); - num += count_skill(m, sk); - } - return num; -} - -static int allied_skilllimit(const faction * f, skill_t sk) -{ - static int value = -1; - if (value < 0) { - value = get_param_int(global.parameters, "alliance.skilllimit", 0); - } - return value; -} - static void init_maxmagicians(struct attrib *a) { a->data.i = MAXMAGICIANS; @@ -454,21 +431,6 @@ static attrib_type at_maxmagicians = { ATF_UNIQUE }; -static void init_npcfaction(struct attrib *a) -{ - a->data.i = 1; -} - -static attrib_type at_npcfaction = { - "npcfaction", - init_npcfaction, - NULL, - NULL, - a_writeint, - a_readint, - ATF_UNIQUE -}; - int max_magicians(const faction * f) { int m = @@ -483,46 +445,20 @@ int max_magicians(const faction * f) return m; } -int skill_limit(faction * f, skill_t sk) +static void init_npcfaction(struct attrib *a) { - int m = INT_MAX; - int al = allied_skilllimit(f, sk); - if (al > 0) { - if (sk != SK_ALCHEMY && sk != SK_MAGIC) - return INT_MAX; - if (f_get_alliance(f)) { - int ac = listlen(f->alliance->members); /* number of factions */ - int fl = (al + ac - 1) / ac; /* faction limit, rounded up */ - /* the faction limit may not be achievable because it would break the alliance-limit */ - int sc = al - allied_skillcount(f, sk); - if (sc <= 0) - return 0; - return fl; - } - } - if (sk == SK_MAGIC) { - m = max_magicians(f); - } else if (sk == SK_ALCHEMY) { - m = get_param_int(global.parameters, "rules.maxskills.alchemy", - MAXALCHEMISTS); - } - return m; + a->data.i = 1; } -int count_skill(faction * f, skill_t sk) -{ - int n = 0; - unit *u; - - for (u = f->units; u; u = u->nextF) { - if (has_skill(u, sk)) { - if (!is_familiar(u)) { - n += u->number; - } - } - } - return n; -} +static attrib_type at_npcfaction = { + "npcfaction", + init_npcfaction, + NULL, + NULL, + a_writeint, + a_readint, + ATF_UNIQUE +}; int verbosity = 1; @@ -738,17 +674,12 @@ region *findunitregion(const unit * su) #endif } -int effskill(const unit * u, skill_t sk) -{ - return eff_skill(u, sk, u->region); -} - int eff_stealth(const unit * u, const region * r) { int e = 0; /* Auf Schiffen keine Tarnung! */ - if (!u->ship && skill_enabled[SK_STEALTH]) { + if (!u->ship && skill_enabled(SK_STEALTH)) { e = eff_skill(u, SK_STEALTH, r); if (fval(u, UFL_STEALTH)) { @@ -949,7 +880,7 @@ cansee(const faction * f, const region * r, const unit * u, int modifier) while (u2) { if (rings < u->number || invisible(u, u2) < u->number) { - if (skill_enabled[SK_PERCEPTION]) { + if (skill_enabled(SK_PERCEPTION)) { int observation = eff_skill(u2, SK_PERCEPTION, r); if (observation >= stealth) { @@ -992,7 +923,7 @@ bool cansee_unit(const unit * u, const unit * target, int modifier) if (rings && invisible(target, u) >= target->number) { return false; } - if (skill_enabled[SK_PERCEPTION]) { + if (skill_enabled(SK_PERCEPTION)) { o = eff_skill(u, SK_PERCEPTION, target->region); if (o >= n) { return true; @@ -1245,25 +1176,6 @@ int findoption(const char *s, const struct locale *lang) return NODIRECTION; } -skill_t findskill(const char *s, const struct locale * lang) -{ - param_t result = NOSKILL; - char buffer[64]; - char * str = transliterate(buffer, sizeof(buffer)-sizeof(int), s); - - if (str) { - int i; - const void * match; - void **tokens = get_translations(lang, UT_SKILLS); - struct critbit_tree *cb = (critbit_tree *)*tokens; - if (cb && cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) { - cb_get_kv(match, &i, sizeof(int)); - result = (skill_t)i; - } - } - return result; -} - param_t findparam(const char *s, const struct locale * lang) { param_t result = NOPARAM; @@ -1626,7 +1538,7 @@ int lighthouse_range(const building * b, const faction * f) if (fval(b, BLD_WORKING) && b->size >= 10) { int maxd = (int)log10(b->size) + 1; - if (skill_enabled[SK_PERCEPTION]) { + if (skill_enabled(SK_PERCEPTION)) { region *r = b->region; int c = 0; unit *u; @@ -1668,7 +1580,7 @@ bool check_leuchtturm(region * r, faction * f) if (fval(b, BLD_WORKING) && b->size >= 10) { int maxd = (int)log10(b->size) + 1; - if (skill_enabled[SK_PERCEPTION]) { + if (skill_enabled(SK_PERCEPTION)) { region *r2 = b->region; unit *u; int c = 0; @@ -1837,12 +1749,6 @@ static const char * parameter_key(int i) return parameters[i]; } -static const char * skill_key(int sk) -{ - assert(sk=0); - return skill_enabled[sk] ? mkname("skill", skillnames[sk]) : 0; -} - static void init_locale(const struct locale *lang) { variant var; @@ -1884,7 +1790,6 @@ static void init_locale(const struct locale *lang) } init_translations(lang, UT_PARAMS, parameter_key, MAXPARAMS); - init_translations(lang, UT_SKILLS, skill_key, MAXSKILLS); tokens = get_translations(lang, UT_OPTIONS); for (i = 0; i != MAXOPTIONS; ++i) { diff --git a/src/kernel/config.h b/src/kernel/config.h index 3aee4b5f8..f7091b581 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -132,16 +132,13 @@ extern "C" { /* parteinummern */ bool faction_id_is_unused(int); +int max_magicians(const struct faction * f); /* leuchtturm */ bool check_leuchtturm(struct region *r, struct faction *f); void update_lighthouse(struct building *lh); int lighthouse_range(const struct building *b, const struct faction *f); -/* skills */ - int skill_limit(struct faction *f, skill_t sk); - int count_skill(struct faction *f, skill_t sk); - int findoption(const char *s, const struct locale *lang); /* special units */ @@ -157,8 +154,6 @@ extern "C" { const char *igetstrtoken(const char *s); - skill_t findskill(const char *s, const struct locale *lang); - param_t findparam(const char *s, const struct locale *lang); param_t findparam_ex(const char *s, const struct locale * lang); bool isparam(const char *s, const struct locale * lang, param_t param); @@ -183,7 +178,6 @@ extern "C" { int modifier); bool seefaction(const struct faction *f, const struct region *r, const struct unit *u, int modifier); - int effskill(const struct unit *u, skill_t sk); int lovar(double xpct_x2); /* returns a value between [0..xpct_2], generated with two dice */ @@ -402,8 +396,6 @@ extern "C" { } settings; extern settings global; - int produceexp(struct unit *u, skill_t sk, int n); - extern bool battledebug; extern bool sqlpatch; extern bool lomem; /* save memory */ @@ -418,7 +410,6 @@ extern "C" { bool ExpensiveMigrants(void); int NMRTimeout(void); int LongHunger(const struct unit *u); - int SkillCap(skill_t sk); int NewbieImmunity(void); bool IsImmune(const struct faction *f); int AllianceAuto(void); /* flags that allied factions get automatically */ diff --git a/src/kernel/equipment.h b/src/kernel/equipment.h index c6fd146c6..9eee8b5d8 100644 --- a/src/kernel/equipment.h +++ b/src/kernel/equipment.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_EQUIPMENT_H #define H_KRNL_EQUIPMENT_H + +#include "skill.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/equipment.test.c b/src/kernel/equipment.test.c index 4c2268178..edc7f92e1 100644 --- a/src/kernel/equipment.test.c +++ b/src/kernel/equipment.test.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include @@ -24,7 +23,7 @@ void test_equipment(CuTest * tc) test_cleanup(); test_create_race("human"); - skill_enabled[SK_MAGIC] = 1; + enable_skill(SK_MAGIC, true); it_horses = test_create_itemtype(names); CuAssertPtrNotNull(tc, it_horses); sp = create_spell("testspell", 0); diff --git a/src/kernel/faction.c b/src/kernel/faction.c index c1ff3cb83..67018796e 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -57,6 +57,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include +#include faction *factions; @@ -518,3 +519,68 @@ struct spellbook * faction_get_spellbook(struct faction *f) } return 0; } + +static int allied_skillcount(const faction * f, skill_t sk) +{ + int num = 0; + alliance *a = f_get_alliance(f); + quicklist *members = a->members; + int qi; + + for (qi = 0; members; ql_advance(&members, &qi, 1)) { + faction *m = (faction *) ql_get(members, qi); + num += count_skill(m, sk); + } + return num; +} + +static int allied_skilllimit(const faction * f, skill_t sk) +{ + static int value = -1; + if (value < 0) { + value = get_param_int(global.parameters, "alliance.skilllimit", 0); + } + return value; +} + +int count_skill(faction * f, skill_t sk) +{ + int n = 0; + unit *u; + + for (u = f->units; u; u = u->nextF) { + if (has_skill(u, sk)) { + if (!is_familiar(u)) { + n += u->number; + } + } + } + return n; +} + +int skill_limit(faction * f, skill_t sk) +{ + int m = INT_MAX; + int al = allied_skilllimit(f, sk); + if (al > 0) { + if (sk != SK_ALCHEMY && sk != SK_MAGIC) + return INT_MAX; + if (f_get_alliance(f)) { + int ac = listlen(f->alliance->members); /* number of factions */ + int fl = (al + ac - 1) / ac; /* faction limit, rounded up */ + /* the faction limit may not be achievable because it would break the alliance-limit */ + int sc = al - allied_skillcount(f, sk); + if (sc <= 0) + return 0; + return fl; + } + } + if (sk == SK_MAGIC) { + m = max_magicians(f); + } else if (sk == SK_ALCHEMY) { + m = get_param_int(global.parameters, "rules.maxskills.alchemy", + MAXALCHEMISTS); + } + return m; +} + diff --git a/src/kernel/faction.h b/src/kernel/faction.h index d72fc8622..e00ceac01 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_FACTION #define H_KRNL_FACTION + +#include "skill.h" + #ifdef __cplusplus extern "C" { #endif @@ -111,6 +114,8 @@ extern "C" { extern struct faction *factions; + int max_magicians(const faction * f); + extern const struct unit *random_unit_in_faction(const struct faction *f); extern const char *factionname(const struct faction *f); extern struct unit *addplayer(struct region *r, faction * f); @@ -151,6 +156,11 @@ extern "C" { bool valid_race(const struct faction *f, const struct race *rc); struct spellbook * faction_get_spellbook(struct faction *f); + +/* skills */ + int skill_limit(struct faction *f, skill_t sk); + int count_skill(struct faction *f, skill_t sk); + #ifdef __cplusplus } #endif diff --git a/src/kernel/item.c b/src/kernel/item.c index f66c6db94..eda08fc7b 100644 --- a/src/kernel/item.c +++ b/src/kernel/item.c @@ -919,7 +919,7 @@ use_magicboost(struct unit *user, const struct item_type *itype, int amount, user->number); a_add(&f->attribs, make_key(atoi36("mbst"))); - set_level(user, sk_find("magic"), 3); + set_level(user, findskill("magic"), 3); ADDMSG(&user->faction->msgs, msg_message("use_item", "unit item", user, itype->rtype)); diff --git a/src/kernel/item.h b/src/kernel/item.h index be6d18272..a18bbaa63 100644 --- a/src/kernel/item.h +++ b/src/kernel/item.h @@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define H_KRNL_ITEM #include +#include "skill.h" #ifdef __cplusplus extern "C" { diff --git a/src/kernel/magic.test.c b/src/kernel/magic.test.c index 2a89de23c..6d7ace6ba 100644 --- a/src/kernel/magic.test.c +++ b/src/kernel/magic.test.c @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -174,7 +173,7 @@ void test_getspell_unit(CuTest * tc) f = test_create_faction(0); u = test_create_unit(f, r); create_mage(u, M_GRAY); - skill_enabled[SK_MAGIC] = 1; + enable_skill(SK_MAGIC, true); set_level(u, SK_MAGIC, 1); @@ -203,7 +202,7 @@ void test_getspell_faction(CuTest * tc) f->magiegebiet = M_TYBIED; u = test_create_unit(f, r); create_mage(u, f->magiegebiet); - skill_enabled[SK_MAGIC] = 1; + enable_skill(SK_MAGIC, true); set_level(u, SK_MAGIC, 1); @@ -234,7 +233,7 @@ void test_getspell_school(CuTest * tc) f->magiegebiet = M_TYBIED; u = test_create_unit(f, r); create_mage(u, f->magiegebiet); - skill_enabled[SK_MAGIC] = 1; + enable_skill(SK_MAGIC, true); set_level(u, SK_MAGIC, 1); lang = get_locale("de"); @@ -263,7 +262,7 @@ void test_set_pre_combatspell(CuTest * tc) f = test_create_faction(0); f->magiegebiet = M_TYBIED; u = test_create_unit(f, r); - skill_enabled[SK_MAGIC] = 1; + enable_skill(SK_MAGIC, true); set_level(u, SK_MAGIC, 1); sp = create_spell("testspell", 0); sp->sptyp |= PRECOMBATSPELL; @@ -295,7 +294,7 @@ void test_set_main_combatspell(CuTest * tc) f = test_create_faction(0); f->magiegebiet = M_TYBIED; u = test_create_unit(f, r); - skill_enabled[SK_MAGIC] = 1; + enable_skill(SK_MAGIC, true); set_level(u, SK_MAGIC, 1); sp = create_spell("testspell", 0); sp->sptyp |= COMBATSPELL; @@ -327,7 +326,7 @@ void test_set_post_combatspell(CuTest * tc) f = test_create_faction(0); f->magiegebiet = M_TYBIED; u = test_create_unit(f, r); - skill_enabled[SK_MAGIC] = 1; + enable_skill(SK_MAGIC, true); set_level(u, SK_MAGIC, 1); sp = create_spell("testspell", 0); sp->sptyp |= POSTCOMBATSPELL; @@ -358,7 +357,7 @@ void test_hasspell(CuTest * tc) f = test_create_faction(0); f->magiegebiet = M_TYBIED; u = test_create_unit(f, r); - skill_enabled[SK_MAGIC] = 1; + enable_skill(SK_MAGIC, true); sp = create_spell("testspell", 0); sp->sptyp |= POSTCOMBATSPELL; diff --git a/src/kernel/order.c b/src/kernel/order.c index a2ea25ff6..2ec616eb6 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -192,7 +192,7 @@ static order_data *create_data(keyword_t kwd, const char *sptr, int lindex) /* learning, only one order_data per skill required */ if (kwd == K_STUDY) { - skill_t sk = findskill(parse_token(&sptr), lang); + skill_t sk = get_skill(parse_token(&sptr), lang); switch (sk) { case NOSKILL: /* fehler */ break; diff --git a/src/kernel/pool.test.c b/src/kernel/pool.test.c index 3b801a9b9..ad700f6a8 100644 --- a/src/kernel/pool.test.c +++ b/src/kernel/pool.test.c @@ -21,7 +21,7 @@ void test_change_resource(CuTest * tc) test_cleanup(); test_create_world(); - skill_enabled[SK_MAGIC] = 1; + enable_skill(SK_MAGIC, true); r = findregion(0, 0); f = test_create_faction(0); diff --git a/src/kernel/race.h b/src/kernel/race.h index 3782fe217..2e6056598 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -23,7 +23,8 @@ extern "C" { #endif #include "magic.h" /* wegen MAXMAGIETYP */ - +#include "skill.h" + #define AT_NONE 0 #define AT_STANDARD 1 #define AT_DRAIN_EXP 2 diff --git a/src/kernel/reports.c b/src/kernel/reports.c index 1c2129047..fb6633be3 100644 --- a/src/kernel/reports.c +++ b/src/kernel/reports.c @@ -36,7 +36,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/kernel/save.c b/src/kernel/save.c index 269833d0e..68efdc7c1 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -664,7 +664,7 @@ unit *read_unit(struct gamedata *data) } else { READ_TOK(data->store, rname, sizeof(rname)); } - if (rname[0] && skill_enabled[SK_STEALTH]) + if (rname[0] && skill_enabled(SK_STEALTH)) u->irace = rc_find(rname); else u->irace = NULL; diff --git a/src/kernel/skill.c b/src/kernel/skills.c similarity index 82% rename from src/kernel/skill.c rename to src/kernel/skills.c index 2cdc3d25b..1bbc7a1e1 100644 --- a/src/kernel/skill.c +++ b/src/kernel/skills.c @@ -41,76 +41,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include -const char *skillnames[MAXSKILLS] = { - "alchemy", - "crossbow", - "mining", - "bow", - "building", - "trade", - "forestry", - "catapult", - "herbalism", - "magic", - "training", - "riding", - "armorer", - "shipcraft", - "melee", - "sailing", - "polearm", - "espionage", - "quarrying", - "roadwork", - "tactics", - "stealth", - "entertainment", - "weaponsmithing", - "cartmaking", - "perception", - "taxation", - "stamina", - "unarmed" -}; - -bool skill_enabled[MAXSKILLS]; - -const char *skillname(skill_t sk, const struct locale *lang) -{ - if (skill_enabled[sk]) { - return locale_string(lang, mkname("skill", skillnames[sk])); - } - return NULL; -} - -void enable_skill(const char *skname, bool value) -{ - skill_t sk; - for (sk = 0; sk != MAXSKILLS; ++sk) { - if (strcmp(skillnames[sk], skname) == 0) { - skill_enabled[sk] = value; - return; - } - } - log_error("Trying to set unknown skill %s to %u", skname, value); -} - -skill_t sk_find(const char *name) -{ - skill_t i; - if (name == NULL) - return NOSKILL; - if (strncmp(name, "sk_", 3) == 0) - name += 3; - for (i = 0; i != MAXSKILLS; ++i) { - if (skill_enabled[i]) { - if (strcmp(name, skillnames[i]) == 0) - return i; - } - } - return NOSKILL; -} - /** skillmod attribut **/ static void init_skillmod(attrib * a) { @@ -223,7 +153,7 @@ int rc_skillmod(const struct race *rc, const region * r, skill_t sk) { int mods = 0; - if (!skill_enabled[sk]) { + if (!skill_enabled(sk)) { return 0; } #ifdef FASTER_SKILLMOD diff --git a/src/kernel/skill.h b/src/kernel/skills.h similarity index 89% rename from src/kernel/skill.h rename to src/kernel/skills.h index 4db618f5a..bc7300c02 100644 --- a/src/kernel/skill.h +++ b/src/kernel/skills.h @@ -12,6 +12,9 @@ #ifndef H_KRNL_SKILL #define H_KRNL_SKILL + +#include + #ifdef __cplusplus extern "C" { #endif @@ -46,9 +49,6 @@ extern "C" { extern struct attrib *make_skillmod(skill_t sk, unsigned int flags, skillmod_fun special, double multiplier, int bonus); - extern const char *skillname(skill_t, const struct locale *); - extern skill_t sk_find(const char *name); - extern void enable_skill(const char *name, bool value); extern int level_days(int level); extern int level(int days); @@ -59,9 +59,6 @@ extern "C" { extern void sk_set(skill * sv, int level); - extern const char *skillnames[]; - extern bool skill_enabled[]; - #ifdef __cplusplus } #endif diff --git a/src/kernel/types.h b/src/kernel/types.h index a2d438b02..a3f2ca94a 100644 --- a/src/kernel/types.h +++ b/src/kernel/types.h @@ -186,42 +186,6 @@ enum { MAXOPTIONS }; -/* ------------------ Talente ---------------------------------- */ - -typedef enum { - SK_ALCHEMY, - SK_CROSSBOW, - SK_MINING, - SK_LONGBOW, - SK_BUILDING, - SK_TRADE, - SK_LUMBERJACK, - SK_CATAPULT, - SK_HERBALISM, - SK_MAGIC, - SK_HORSE_TRAINING, /* 10 */ - SK_RIDING, - SK_ARMORER, - SK_SHIPBUILDING, - SK_MELEE, - SK_SAILING, - SK_SPEAR, - SK_SPY, - SK_QUARRYING, - SK_ROAD_BUILDING, - SK_TACTICS, /* 20 */ - SK_STEALTH, - SK_ENTERTAINMENT, - SK_WEAPONSMITH, - SK_CARTMAKER, - SK_PERCEPTION, - SK_TAXING, - SK_STAMINA, - SK_WEAPONLESS, - MAXSKILLS, - NOSKILL = -1 -} skill_t; - /* ------------- Typ von Einheiten ----------------------------- */ typedef enum { diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 8f7f20262..b267136aa 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -679,7 +679,7 @@ attrib_type at_stealth = { void u_seteffstealth(unit * u, int value) { - if (skill_enabled[SK_STEALTH]) { + if (skill_enabled(SK_STEALTH)) { attrib *a = NULL; if (fval(u, UFL_STEALTH)) { a = a_find(u->attribs, &at_stealth); @@ -701,7 +701,7 @@ void u_seteffstealth(unit * u, int value) int u_geteffstealth(const struct unit *u) { - if (skill_enabled[SK_STEALTH]) { + if (skill_enabled(SK_STEALTH)) { if (fval(u, UFL_STEALTH)) { attrib *a = a_find(u->attribs, &at_stealth); if (a != NULL) @@ -713,7 +713,7 @@ int u_geteffstealth(const struct unit *u) int get_level(const unit * u, skill_t id) { - if (skill_enabled[id]) { + if (skill_enabled(id)) { skill *sv = u->skills; while (sv != u->skills + u->skill_size) { if (sv->id == id) { @@ -729,7 +729,7 @@ void set_level(unit * u, skill_t sk, int value) { skill *sv = u->skills; - if (!skill_enabled[sk]) + if (!skill_enabled(sk)) return; if (value == 0) { @@ -939,8 +939,8 @@ void transfermen(unit * u, unit * u2, int n) for (sk = 0; sk != MAXSKILLS; ++sk) { int weeks, level = 0; - sv = get_skill(u, sk); - sn = get_skill(u2, sk); + sv = unit_skill(u, sk); + sn = unit_skill(u2, sk); if (sv == NULL && sn == NULL) continue; @@ -1185,7 +1185,7 @@ skill *add_skill(unit * u, skill_t id) return sv; } -skill *get_skill(const unit * u, skill_t sk) +skill *unit_skill(const unit * u, skill_t sk) { skill *sv = u->skills; while (sv != u->skills + u->skill_size) { @@ -1326,7 +1326,7 @@ get_modifier(const unit * u, skill_t sk, int level, const region * r, int eff_skill(const unit * u, skill_t sk, const region * r) { - if (skill_enabled[sk]) { + if (skill_enabled(sk)) { int level = get_level(u, sk); if (level > 0) { int mlevel = level + get_modifier(u, sk, level, r, false); @@ -1740,7 +1740,7 @@ void scale_number(unit * u, int n) const struct race *u_irace(const struct unit *u) { - if (u->irace && skill_enabled[SK_STEALTH]) { + if (u->irace && skill_enabled(SK_STEALTH)) { return u->irace; } return u->race_; @@ -1784,3 +1784,9 @@ struct spellbook * unit_get_spellbook(const struct unit * u) } return 0; } + +int effskill(const unit * u, skill_t sk) +{ + return eff_skill(u, sk, u->region); +} + diff --git a/src/kernel/unit.h b/src/kernel/unit.h index 145e7ef5d..0826fb786 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -21,7 +21,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "types.h" - +#include "skills.h" #ifdef __cplusplus extern "C" { #endif @@ -155,11 +155,14 @@ extern "C" { struct unit *findnewunit(const struct region *r, const struct faction *f, int alias); - extern const char *u_description(const unit * u, const struct locale *lang); - extern struct skill *add_skill(struct unit *u, skill_t id); - extern void remove_skill(struct unit *u, skill_t sk); - extern struct skill *get_skill(const struct unit *u, skill_t id); - extern bool has_skill(const unit * u, skill_t sk); + const char *u_description(const unit * u, const struct locale *lang); + struct skill *add_skill(struct unit *u, skill_t id); + void remove_skill(struct unit *u, skill_t sk); + struct skill *unit_skill(const struct unit *u, skill_t id); + bool has_skill(const unit * u, skill_t sk); + int effskill(const struct unit *u, skill_t sk); + int produceexp(struct unit *u, skill_t sk, int n); + int SkillCap(skill_t sk); extern void set_level(struct unit *u, skill_t id, int level); extern int get_level(const struct unit *u, skill_t id); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 63d8a7164..4cc8ba358 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -24,7 +24,7 @@ without prior permission by the authors of Eressea. #include "resources.h" #include "ship.h" #include "terrain.h" -#include "skill.h" +#include "skills.h" #include "spell.h" #include "spellbook.h" #include "calendar.h" @@ -164,7 +164,7 @@ xml_readconstruction(xmlXPathContextPtr xpath, xmlNodeSetPtr nodeSet, propValue = xmlGetProp(node, BAD_CAST "skill"); if (propValue != NULL) { - sk = sk_find((const char *)propValue); + sk = findskill((const char *)propValue); if (sk == NOSKILL) { log_error("construction requires skill '%s' that does not exist.\n", (const char *)propValue); xmlFree(propValue); @@ -698,7 +698,7 @@ static weapon_type *xml_readweapon(xmlXPathContextPtr xpath, item_type * itype) propValue = xmlGetProp(node, BAD_CAST "skill"); assert(propValue != NULL); - sk = sk_find((const char *)propValue); + sk = findskill((const char *)propValue); assert(sk != NOSKILL); xmlFree(propValue); @@ -1295,7 +1295,7 @@ static void add_skills(equipment * eq, xmlNodeSetPtr nsetSkills) propValue = xmlGetProp(node, BAD_CAST "name"); assert(propValue != NULL); - sk = sk_find((const char *)propValue); + sk = findskill((const char *)propValue); if (sk == NOSKILL) { log_error("unknown skill '%s' in equipment-set %s\n", (const char *)propValue, eq->name); xmlFree(propValue); @@ -1819,7 +1819,7 @@ static int parse_races(xmlDocPtr doc) propValue = xmlGetProp(node, BAD_CAST "name"); assert(propValue != NULL); - sk = sk_find((const char *)propValue); + sk = findskill((const char *)propValue); if (sk != NOSKILL) { rc->bonus[sk] = (char)mod; if (speed) { @@ -2324,8 +2324,11 @@ static int parse_main(xmlDocPtr doc) for (i = 0; i != nodes->nodeNr; ++i) { xmlNodePtr node = nodes->nodeTab[i]; xmlChar *propName = xmlGetProp(node, BAD_CAST "name"); - bool enable = xml_bvalue(node, "enable", true); - enable_skill((const char *)propName, enable); + skill_t sk = findskill((const char *)propName); + if (sk!=NOSKILL) { + bool enable = xml_bvalue(node, "enable", true); + enable_skill(sk, enable); + } xmlFree(propName); } } diff --git a/src/keyword.c b/src/keyword.c index 7f8516fdc..95e9530ec 100644 --- a/src/keyword.c +++ b/src/keyword.c @@ -22,6 +22,10 @@ void init_keyword(const struct locale *lang, keyword_t kwd, const char *str) { add_translation(cb, str, (int)kwd); } +void init_keywords(const struct locale *lang) { + init_translations(lang, UT_KEYWORDS, keyword_key, MAXKEYWORDS); +} + keyword_t findkeyword(const char *s) { int i; for (i=0;i!=MAXKEYWORDS;++i) { @@ -32,11 +36,6 @@ keyword_t findkeyword(const char *s) { return NOKEYWORD; } - -void init_keywords(const struct locale *lang) { - init_translations(lang, UT_KEYWORDS, keyword_key, MAXKEYWORDS); -} - keyword_t get_keyword(const char *s, const struct locale *lang) { keyword_t result = NOKEYWORD; char buffer[64]; diff --git a/src/laws.c b/src/laws.c index a3d41d058..39dcdebb4 100755 --- a/src/laws.c +++ b/src/laws.c @@ -54,7 +54,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/modules/arena.c b/src/modules/arena.c index e9edd31e8..88a85b4bc 100644 --- a/src/modules/arena.c +++ b/src/modules/arena.c @@ -41,7 +41,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/modules/dungeon.c b/src/modules/dungeon.c index 4a8b384cd..6e9508554 100644 --- a/src/modules/dungeon.c +++ b/src/modules/dungeon.c @@ -206,7 +206,7 @@ static int tagbegin(xml_stack * stack) } else { dungeon *d = (dungeon *) stack->state; if (strcmp(tag->name, "skilllimit") == 0) { - skill_t sk = sk_find(xml_value(tag, "name")); + skill_t sk = findskill(xml_value(tag, "name")); if (sk != NOSKILL) { skilllimit *skl = calloc(sizeof(skilllimit), 1); skl->skill = sk; diff --git a/src/modules/score.c b/src/modules/score.c index 6d0163691..ccadf3eb5 100644 --- a/src/modules/score.c +++ b/src/modules/score.c @@ -30,7 +30,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include diff --git a/src/monster.c b/src/monster.c index 3118d7d93..222ee6be5 100644 --- a/src/monster.c +++ b/src/monster.c @@ -45,7 +45,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/monsters.c b/src/monsters.c index f876bdf88..543ea3fc1 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -48,7 +48,6 @@ #include #include #include -#include #include #include #include @@ -729,7 +728,7 @@ static order *plan_dragon(unit * u) if (long_order == NULL) { skill_t sk = SK_PERCEPTION; /* study perception (or a random useful skill) */ - while (!skill_enabled[sk] || u_race(u)->bonus[sk] < -5) { + while (!skill_enabled(sk) || u_race(u)->bonus[sk] < -5) { sk = (skill_t) (rng_int() % MAXSKILLS); } long_order = create_order(K_STUDY, u->faction->locale, "'%s'", @@ -768,7 +767,7 @@ void plan_monsters(faction * f) setstatus(u, ST_FIGHT); /* all monsters fight */ } - if (skill_enabled[SK_PERCEPTION]) { + if (skill_enabled(SK_PERCEPTION)) { /* Monster bekommen jede Runde ein paar Tage Wahrnehmung dazu */ /* TODO: this only works for playerrace */ produceexp(u, SK_PERCEPTION, u->number); diff --git a/src/randenc.c b/src/randenc.c index 7fc7ad943..7233c224d 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -41,7 +41,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include diff --git a/src/report.c b/src/report.c index f0cf5eb10..ea5aec089 100644 --- a/src/report.c +++ b/src/report.c @@ -60,7 +60,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include #include @@ -1292,7 +1291,7 @@ static void statistics(FILE * F, const region * r, const faction * f) rnl(F); /* Region */ - if (skill_enabled[SK_ENTERTAINMENT] && fval(r->terrain, LAND_REGION) + if (skill_enabled(SK_ENTERTAINMENT) && fval(r->terrain, LAND_REGION) && rmoney(r)) { m = msg_message("nr_stat_maxentertainment", "max", entertainmoney(r)); nr_render(m, f->locale, buf, sizeof(buf), f); diff --git a/src/skill.c b/src/skill.c new file mode 100644 index 000000000..b5aede0bb --- /dev/null +++ b/src/skill.c @@ -0,0 +1,109 @@ +#include +#include +#include "skill.h" + +#include +#include +#include +#include + +#include +#include + +const char *skillnames[MAXSKILLS] = { + "alchemy", + "crossbow", + "mining", + "bow", + "building", + "trade", + "forestry", + "catapult", + "herbalism", + "magic", + "training", + "riding", + "armorer", + "shipcraft", + "melee", + "sailing", + "polearm", + "espionage", + "quarrying", + "roadwork", + "tactics", + "stealth", + "entertainment", + "weaponsmithing", + "cartmaking", + "perception", + "taxation", + "stamina", + "unarmed" +}; + +bool skill_disabled[MAXSKILLS]; + +bool skill_enabled(skill_t sk) { + return !skill_disabled[sk]; +} + +static const char * skill_key(int sk) { + assert(sk=0); + return skill_disabled[sk] ? 0 : mkname("skill", skillnames[sk]); +} + +void init_skill(const struct locale *lang, skill_t kwd, const char *str) { + void **tokens = get_translations(lang, UT_SKILLS); + struct critbit_tree **cb = (critbit_tree **)tokens; + add_translation(cb, str, (int)kwd); +} + +void init_skills(const struct locale *lang) { + init_translations(lang, UT_SKILLS, skill_key, MAXSKILLS); +} + +const char *skillname(skill_t sk, const struct locale *lang) +{ + if (skill_disabled[sk]) return 0; + return locale_string(lang, mkname("skill", skillnames[sk])); + +} + +void enable_skill(skill_t sk, bool value) +{ + skill_disabled[sk] = !value; +} + +skill_t findskill(const char *name) +{ + skill_t i; + if (name == NULL) return NOSKILL; + if (strncmp(name, "sk_", 3) == 0) name += 3; + for (i = 0; i != MAXSKILLS; ++i) { + if (!skill_disabled[i] && strcmp(name, skillnames[i]) == 0) { + return i; + } + } + return NOSKILL; +} + +skill_t get_skill(const char *s, const struct locale * lang) +{ + param_t result = NOSKILL; + char buffer[64]; + char * str = transliterate(buffer, sizeof(buffer)-sizeof(int), s); + + if (str) { + int i; + const void * match; + void **tokens = get_translations(lang, UT_SKILLS); + struct critbit_tree *cb = (critbit_tree *)*tokens; + if (cb && cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) { + cb_get_kv(match, &i, sizeof(int)); + result = (skill_t)i; + } + } + return result; +} + diff --git a/src/skill.h b/src/skill.h new file mode 100644 index 000000000..aa1727a4d --- /dev/null +++ b/src/skill.h @@ -0,0 +1,50 @@ +#ifndef H_SKILL_H +#define H_SKILL_H + +struct locale; + +typedef enum { + SK_ALCHEMY, + SK_CROSSBOW, + SK_MINING, + SK_LONGBOW, + SK_BUILDING, + SK_TRADE, + SK_LUMBERJACK, + SK_CATAPULT, + SK_HERBALISM, + SK_MAGIC, + SK_HORSE_TRAINING, /* 10 */ + SK_RIDING, + SK_ARMORER, + SK_SHIPBUILDING, + SK_MELEE, + SK_SAILING, + SK_SPEAR, + SK_SPY, + SK_QUARRYING, + SK_ROAD_BUILDING, + SK_TACTICS, /* 20 */ + SK_STEALTH, + SK_ENTERTAINMENT, + SK_WEAPONSMITH, + SK_CARTMAKER, + SK_PERCEPTION, + SK_TAXING, + SK_STAMINA, + SK_WEAPONLESS, + MAXSKILLS, + NOSKILL = -1 +} skill_t; + +extern const char *skillnames[]; + +skill_t get_skill(const char *s, const struct locale *lang); +const char *skillname(skill_t, const struct locale *); +skill_t findskill(const char *name); +void init_skills(const struct locale *lang); +void init_skill(const struct locale *lang, skill_t kwd, const char *str); +void enable_skill(skill_t sk, bool enabled); +bool skill_enabled(skill_t sk); + +#endif diff --git a/src/skill.test.c b/src/skill.test.c new file mode 100644 index 000000000..00c884edc --- /dev/null +++ b/src/skill.test.c @@ -0,0 +1,59 @@ +#include +#include "kernel/types.h" +#include "skill.h" +#include "util/language.h" +#include "tests.h" + +#include + +static void test_init_skills(CuTest *tc) { + struct locale *lang; + + test_cleanup(); + lang = get_or_create_locale("de"); + locale_setstring(lang, "alchemy", "Alchemie"); + init_skills(lang); + CuAssertIntEquals(tc, SK_ALCHEMY, get_skill("alchemie", lang)); + test_cleanup(); +} + +static void test_init_skill(CuTest *tc) { + struct locale *lang; + test_cleanup(); + + lang = get_or_create_locale("de"); + init_skill(lang, SK_ALCHEMY, "Alchemie"); + CuAssertIntEquals(tc, SK_ALCHEMY, get_skill("alchemie", lang)); + CuAssertIntEquals(tc, NOSKILL, get_skill("east", lang)); + test_cleanup(); +} + +static void test_get_skill(CuTest *tc) { + test_cleanup(); + CuAssertIntEquals(tc, SK_ALCHEMY, findskill("alchemy")); + CuAssertIntEquals(tc, SK_CROSSBOW, findskill("crossbow")); + CuAssertIntEquals(tc, NOSKILL, findskill("")); + CuAssertIntEquals(tc, NOSKILL, findskill("potato")); +} + +static void test_get_skill_default(CuTest *tc) { + struct locale *lang; + test_cleanup(); + lang = get_or_create_locale("en"); + CuAssertIntEquals(tc, NOSKILL, get_skill("potato", lang)); + CuAssertIntEquals(tc, SK_ALCHEMY, get_skill("alchemy", lang)); + CuAssertIntEquals(tc, SK_CROSSBOW, get_skill("crossbow", lang)); +} + +#define SUITE_DISABLE_TEST(suite, test) (void)test + +CuSuite *get_skill_suite(void) +{ + CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_init_skill); + SUITE_ADD_TEST(suite, test_init_skills); + SUITE_ADD_TEST(suite, test_get_skill); + SUITE_DISABLE_TEST(suite, test_get_skill_default); + return suite; +} + diff --git a/src/spells/alp.c b/src/spells/alp.c index 7dc6e53fc..9a9fe4ad9 100644 --- a/src/spells/alp.c +++ b/src/spells/alp.c @@ -21,7 +21,6 @@ #include #include #include -#include #include /* util includes */ diff --git a/src/spells/combatspells.c b/src/spells/combatspells.c index b02316b77..e6d0cb2c6 100644 --- a/src/spells/combatspells.c +++ b/src/spells/combatspells.c @@ -31,7 +31,6 @@ #include #include #include -#include #include /* util includes */ @@ -596,7 +595,7 @@ int sp_mindblast(struct castorder * co) if (!is_magic_resistant(mage, du, 0)) { skill_t sk = random_skill(du, false); if (sk != NOSKILL) { - skill *sv = get_skill(du, sk); + skill *sv = unit_skill(du, sk); int n = 1 + rng_int() % 3; reduce_skill(du, sv, n); diff --git a/src/spells/spells.c b/src/spells/spells.c index daa4f7a81..cd2d6d03a 100644 --- a/src/spells/spells.c +++ b/src/spells/spells.c @@ -46,7 +46,6 @@ #include #include #include -#include #include #include #include @@ -562,12 +561,12 @@ static int sp_summon_familiar(castorder * co) dh = 0; dh1 = 0; for (sk = 0; sk < MAXSKILLS; ++sk) { - if (skill_enabled[sk] && rc->bonus[sk] > -5) + if (skill_enabled(sk) && rc->bonus[sk] > -5) dh++; } for (sk = 0; sk < MAXSKILLS; sk++) { - if (skill_enabled[sk] && rc->bonus[sk] > -5) { + if (skill_enabled(sk) && rc->bonus[sk] > -5) { dh--; if (dh1 == 0) { dh1 = 1; diff --git a/src/spells/unitcurse.c b/src/spells/unitcurse.c index b996c5563..155842e2f 100644 --- a/src/spells/unitcurse.c +++ b/src/spells/unitcurse.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include diff --git a/src/spy.c b/src/spy.c index c97b38c55..a01fbe19c 100644 --- a/src/spy.c +++ b/src/spy.c @@ -32,7 +32,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include diff --git a/src/study.c b/src/study.c index 8c6fbc48c..61f6db74d 100644 --- a/src/study.c +++ b/src/study.c @@ -36,7 +36,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include @@ -60,7 +59,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. static skill_t getskill(const struct locale *lang) { - return findskill(getstrtoken(), lang); + return get_skill(getstrtoken(), lang); } magic_t getmagicskill(const struct locale * lang) @@ -163,7 +162,7 @@ static int study_days(unit * student, skill_t sk) if (u_race(student)->study_speed) { speed += u_race(student)->study_speed[sk]; if (speed < 30) { - skill *sv = get_skill(student, sk); + skill *sv = unit_skill(student, sk); if (sv == 0) { speed = 30; } @@ -566,7 +565,7 @@ int learn_cmd(unit * u, order * ord) return 0; } if (learn_newskills == 0) { - skill *sv = get_skill(u, sk); + skill *sv = unit_skill(u, sk); if (sv == NULL) { /* we can only learn skills we already have */ cmistake(u, ord, 771, MSG_EVENT); diff --git a/src/study.h b/src/study.h index 182e364ee..1783e1a28 100644 --- a/src/study.h +++ b/src/study.h @@ -19,6 +19,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_STUDY #define H_KRNL_STUDY +#include "skill.h" + #ifdef __cplusplus extern "C" { #endif diff --git a/src/summary.c b/src/summary.c index f7a33444b..ef7a49bbc 100644 --- a/src/summary.c +++ b/src/summary.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include diff --git a/src/test_eressea.c b/src/test_eressea.c index 2f359f7ac..82f75b6c6 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -26,6 +26,7 @@ CuSuite *get_functions_suite(void); CuSuite *get_umlaut_suite(void); CuSuite *get_ally_suite(void); CuSuite *get_direction_suite(void); +CuSuite *get_skill_suite(void); CuSuite *get_keyword_suite(void); int RunAllTests(void) @@ -41,6 +42,7 @@ int RunAllTests(void) CuSuiteAddSuite(suite, get_json_suite()); CuSuiteAddSuite(suite, get_jsonconf_suite()); CuSuiteAddSuite(suite, get_direction_suite()); + CuSuiteAddSuite(suite, get_skill_suite()); CuSuiteAddSuite(suite, get_keyword_suite()); /* util */ CuSuiteAddSuite(suite, get_base36_suite()); diff --git a/src/triggers/shock.c b/src/triggers/shock.c index 489966905..874c6d22b 100644 --- a/src/triggers/shock.c +++ b/src/triggers/shock.c @@ -25,7 +25,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include