diff --git a/src/buildno.h b/src/buildno.h index c494bb5ee..11bf425d6 100644 --- a/src/buildno.h +++ b/src/buildno.h @@ -1,3 +1,3 @@ #define VERSION_MAJOR 3 #define VERSION_MINOR 6 -#define VERSION_BUILD 3 +#define VERSION_BUILD 4 diff --git a/src/kernel/curse.c b/src/kernel/curse.c index afa8ac2c3..828552a3a 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -131,7 +131,7 @@ int curse_age(attrib * a) else if (c->duration != INT_MAX) { c->duration = _max(0, c->duration - 1); } - return c->duration; + return (c->duration > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; } void destroy_curse(curse * c) diff --git a/src/kernel/unit.test.c b/src/kernel/unit.test.c index a76b5ea69..d962fee51 100644 --- a/src/kernel/unit.test.c +++ b/src/kernel/unit.test.c @@ -239,6 +239,31 @@ static void test_default_name(CuTest *tc) { test_cleanup(); } +static void test_skill_hunger(CuTest *tc) { + unit *u; + + test_cleanup(); + u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); + set_level(u, SK_ARMORER, 6); + set_level(u, SK_SAILING, 6); + fset(u, UFL_HUNGER); + + set_param(&global.parameters, "rules.hunger.reduces_skill", "0"); + CuAssertIntEquals(tc, 6, effskill(u, SK_ARMORER)); + CuAssertIntEquals(tc, 6, effskill(u, SK_SAILING)); + + set_param(&global.parameters, "rules.hunger.reduces_skill", "1"); + CuAssertIntEquals(tc, 3, effskill(u, SK_ARMORER)); + CuAssertIntEquals(tc, 3, effskill(u, SK_SAILING)); + + set_param(&global.parameters, "rules.hunger.reduces_skill", "2"); + CuAssertIntEquals(tc, 3, effskill(u, SK_ARMORER)); + CuAssertIntEquals(tc, 5, effskill(u, SK_SAILING)); + set_level(u, SK_SAILING, 2); + CuAssertIntEquals(tc, 1, effskill(u, SK_SAILING)); + test_cleanup(); +} + static void test_skill_familiar(CuTest *tc) { unit *mag, *fam; region *r; @@ -267,6 +292,29 @@ static void test_skill_familiar(CuTest *tc) { test_cleanup(); } +static void test_age_familiar(CuTest *tc) { + unit *mag, *fam; + + test_cleanup(); + + // setup two units + mag = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); + fam = test_create_unit(mag->faction, test_create_region(0, 0, 0)); + CuAssertPtrEquals(tc, 0, get_familiar(mag)); + CuAssertPtrEquals(tc, 0, get_familiar_mage(fam)); + CuAssertIntEquals(tc, true, create_newfamiliar(mag, fam)); + CuAssertPtrEquals(tc, fam, get_familiar(mag)); + CuAssertPtrEquals(tc, mag, get_familiar_mage(fam)); + a_age(&fam->attribs); + a_age(&mag->attribs); + CuAssertPtrEquals(tc, fam, get_familiar(mag)); + CuAssertPtrEquals(tc, mag, get_familiar_mage(fam)); + set_number(fam, 0); + a_age(&mag->attribs); + CuAssertPtrEquals(tc, 0, get_familiar(mag)); + test_cleanup(); +} + CuSuite *get_unit_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -281,6 +329,8 @@ CuSuite *get_unit_suite(void) SUITE_ADD_TEST(suite, test_remove_empty_units_in_region); SUITE_ADD_TEST(suite, test_names); SUITE_ADD_TEST(suite, test_default_name); + SUITE_ADD_TEST(suite, test_skill_hunger); SUITE_ADD_TEST(suite, test_skill_familiar); + SUITE_ADD_TEST(suite, test_age_familiar); return suite; } diff --git a/src/util/attrib.c b/src/util/attrib.c index fb50d8dfc..26869cfee 100644 --- a/src/util/attrib.c +++ b/src/util/attrib.c @@ -256,7 +256,7 @@ int a_age(attrib ** p) if (a->type->age) { int result = a->type->age(a); assert(result >= 0 || !"age() returned a negative value"); - if (result == 0) { + if (result == AT_AGE_REMOVE) { a_remove(p, a); continue; } diff --git a/src/util/attrib.h b/src/util/attrib.h index cbba4ebf4..c235fd67a 100644 --- a/src/util/attrib.h +++ b/src/util/attrib.h @@ -90,8 +90,8 @@ extern "C" { #define AT_READ_OK 0 #define AT_READ_FAIL -1 -#define AT_AGE_KEEP 0 /* keep the attribute for another turn */ -#define AT_AGE_REMOVE 1 /* remove the attribute after calling age() */ +#define AT_AGE_REMOVE 0 /* remove the attribute after calling age() */ +#define AT_AGE_KEEP 1 /* keep the attribute for another turn */ #ifdef __cplusplus }