forked from github/server
deprecate learn_skill taking a double
- introduce days-based learn_skill - add a simple test
This commit is contained in:
parent
cae966f4fe
commit
b5a4faa745
|
@ -28,7 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
void academy_teaching_bonus(struct unit *u, skill_t sk, int academy) {
|
||||
if (academy && sk != NOSKILL) {
|
||||
academy = academy / 30; /* anzahl gelehrter wochen, max. 10 */
|
||||
learn_skill(u, sk, academy / 30.0 / TEACHNUMBER);
|
||||
learn_skill_depr(u, sk, academy / 30.0 / TEACHNUMBER);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -397,7 +397,7 @@ static int tolua_learn_skill(lua_State * L)
|
|||
float chances = (float)tolua_tonumber(L, 3, 0);
|
||||
skill_t sk = findskill(skname);
|
||||
if (sk != NOSKILL) {
|
||||
learn_skill(u, sk, chances);
|
||||
learn_skill_depr(u, sk, chances);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1119,7 +1119,7 @@ int tolua_bindings_open(lua_State * L)
|
|||
tolua_function(L, TOLUA_CAST "update_subscriptions", tolua_update_subscriptions);
|
||||
tolua_function(L, TOLUA_CAST "update_scores", tolua_update_scores);
|
||||
tolua_function(L, TOLUA_CAST "update_owners", tolua_update_owners);
|
||||
tolua_function(L, TOLUA_CAST "learn_skill", tolua_learn_skill);
|
||||
tolua_function(L, TOLUA_CAST "learn_skill_depr", tolua_learn_skill);
|
||||
tolua_function(L, TOLUA_CAST "create_curse", tolua_create_curse);
|
||||
tolua_function(L, TOLUA_CAST "autoseed", tolua_autoseed);
|
||||
tolua_function(L, TOLUA_CAST "get_key", tolua_getkey);
|
||||
|
|
|
@ -55,7 +55,7 @@ struct order *ord)
|
|||
while (sv != u->skills + u->skill_size) {
|
||||
int i;
|
||||
for (i = 0; i != 3; ++i)
|
||||
learn_skill(u, (skill_t)sv->id, 1.0);
|
||||
learn_skill_depr(u, (skill_t)sv->id, 1.0);
|
||||
++sv;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,17 +31,17 @@ static void test_skillpotion(CuTest *tc) {
|
|||
itype = test_create_itemtype("skillpotion");
|
||||
change_resource(u, itype->rtype, 2);
|
||||
|
||||
learn_skill(u, SK_ENTERTAINMENT, 1.0);
|
||||
learn_skill_depr(u, SK_ENTERTAINMENT, 1.0);
|
||||
pSkill = unit_skill(u, SK_ENTERTAINMENT);
|
||||
sk_set(pSkill, 5);
|
||||
initialWeeks_Entertainment = pSkill->weeks = 4;
|
||||
|
||||
learn_skill(u, SK_STAMINA, 1.0);
|
||||
learn_skill_depr(u, SK_STAMINA, 1.0);
|
||||
pSkill = unit_skill(u, SK_STAMINA);
|
||||
sk_set(pSkill, 5);
|
||||
initialWeeks_Stamina = pSkill->weeks = 4;
|
||||
|
||||
learn_skill(u, SK_MAGIC, 1.0);
|
||||
learn_skill_depr(u, SK_MAGIC, 1.0);
|
||||
pSkill = unit_skill(u, SK_MAGIC);
|
||||
sk_set(pSkill, 5);
|
||||
initialWeeks_Magic = pSkill->weeks = 4;
|
||||
|
|
|
@ -160,7 +160,7 @@ static int improve_all(faction * f, skill_t sk, int by_weeks)
|
|||
if (has_skill(u, sk)) {
|
||||
int weeks = 0;
|
||||
for (; weeks != by_weeks; ++weeks) {
|
||||
learn_skill(u, sk, 1.0);
|
||||
learn_skill_depr(u, sk, 1.0);
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ void find_manual(region * r, unit * u)
|
|||
if (improve_all(u->faction, skill, 3) == 3) {
|
||||
int i;
|
||||
for (i = 0; i != 9; ++i)
|
||||
learn_skill(u, skill, 1.0);
|
||||
learn_skill_depr(u, skill, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -984,7 +984,7 @@ static void demon_skillchanges(void)
|
|||
}
|
||||
else {
|
||||
while (weeks--) {
|
||||
learn_skill(u, sv->id, 1.0);
|
||||
learn_skill_depr(u, sv->id, 1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
17
src/study.c
17
src/study.c
|
@ -740,12 +740,12 @@ int study_cmd(unit * u, order * ord)
|
|||
|
||||
while (days) {
|
||||
if (days >= u->number * 30) {
|
||||
learn_skill(u, sk, 1.0);
|
||||
learn_skill_depr(u, sk, 1.0);
|
||||
days -= u->number * 30;
|
||||
}
|
||||
else {
|
||||
double chance = (double)days / u->number / 30;
|
||||
learn_skill(u, sk, chance);
|
||||
learn_skill_depr(u, sk, chance);
|
||||
days = 0;
|
||||
}
|
||||
}
|
||||
|
@ -816,7 +816,7 @@ void produceexp_ex(struct unit *u, skill_t sk, int n, bool(*learn)(unit *, skill
|
|||
|
||||
void produceexp(struct unit *u, skill_t sk, int n)
|
||||
{
|
||||
produceexp_ex(u, sk, n, learn_skill);
|
||||
produceexp_ex(u, sk, n, learn_skill_depr);
|
||||
}
|
||||
|
||||
#ifndef NO_TESTS
|
||||
|
@ -827,7 +827,7 @@ void inject_learn(learn_fun fun) {
|
|||
}
|
||||
#endif
|
||||
|
||||
bool learn_skill(unit * u, skill_t sk, double learn_chance)
|
||||
bool learn_skill_depr(unit * u, skill_t sk, double learn_chance)
|
||||
{
|
||||
skill *sv = u->skills;
|
||||
#ifndef NO_TESTS
|
||||
|
@ -855,3 +855,12 @@ bool learn_skill(unit * u, skill_t sk, double learn_chance)
|
|||
sk_set(sv, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
void learn_skill(unit *u, skill_t sk, int days) {
|
||||
double ch = days*1.0 / STUDYDAYS;
|
||||
while (ch >= 1.0) {
|
||||
learn_skill_depr(u, sk, 1.0);
|
||||
ch -= 1.0;
|
||||
}
|
||||
learn_skill_depr(u, sk, ch);
|
||||
}
|
||||
|
|
|
@ -39,10 +39,14 @@ extern "C" {
|
|||
typedef bool(*learn_fun)(struct unit *u, skill_t sk, double ch);
|
||||
void inject_learn(learn_fun fun);
|
||||
#endif
|
||||
bool learn_skill(struct unit *u, skill_t sk, double chance);
|
||||
|
||||
#define STUDYDAYS 30
|
||||
bool learn_skill_depr(struct unit *u, skill_t sk, double chance);
|
||||
void learn_skill(struct unit *u, skill_t sk, int days);
|
||||
|
||||
void produceexp(struct unit *u, skill_t sk, int n);
|
||||
void produceexp_ex(struct unit *u, skill_t sk, int n, bool(*learn)(struct unit *, skill_t, double));
|
||||
|
||||
#define MAXTEACHERS 20
|
||||
#define TEACHNUMBER 10
|
||||
typedef struct teaching_info {
|
||||
|
|
|
@ -229,9 +229,28 @@ static void test_academy_building(CuTest *tc) {
|
|||
test_cleanup();
|
||||
}
|
||||
|
||||
void test_learn_skill(CuTest *tc) {
|
||||
unit *u;
|
||||
skill *sv;
|
||||
test_cleanup();
|
||||
u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
|
||||
learn_skill(u, SK_ALCHEMY, STUDYDAYS);
|
||||
CuAssertPtrNotNull(tc, sv = u->skills);
|
||||
CuAssertIntEquals(tc, SK_ALCHEMY, sv->id);
|
||||
CuAssertIntEquals(tc, 1, sv->level);
|
||||
CuAssertIntEquals(tc, 2, sv->weeks);
|
||||
learn_skill(u, SK_ALCHEMY, STUDYDAYS);
|
||||
CuAssertIntEquals(tc, 1, sv->weeks);
|
||||
learn_skill(u, SK_ALCHEMY, STUDYDAYS * 2);
|
||||
CuAssertIntEquals(tc, 2, sv->level);
|
||||
CuAssertIntEquals(tc, 1, sv->weeks);
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_study_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_learn_skill);
|
||||
SUITE_ADD_TEST(suite, test_study_no_teacher);
|
||||
SUITE_ADD_TEST(suite, test_study_with_teacher);
|
||||
SUITE_ADD_TEST(suite, test_study_with_bad_teacher);
|
||||
|
|
Loading…
Reference in New Issue