Merge pull request #303 from ennorehling/hotfix/bug-2138-familiarmage

bug 2138 familiarmage
This commit is contained in:
Enno Rehling 2015-09-23 18:37:48 +02:00
commit af5909a9c3
5 changed files with 55 additions and 5 deletions

View file

@ -1,3 +1,3 @@
#define VERSION_MAJOR 3 #define VERSION_MAJOR 3
#define VERSION_MINOR 6 #define VERSION_MINOR 6
#define VERSION_BUILD 3 #define VERSION_BUILD 4

View file

@ -131,7 +131,7 @@ int curse_age(attrib * a)
else if (c->duration != INT_MAX) { else if (c->duration != INT_MAX) {
c->duration = _max(0, c->duration - 1); 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) void destroy_curse(curse * c)

View file

@ -239,6 +239,31 @@ static void test_default_name(CuTest *tc) {
test_cleanup(); 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) { static void test_skill_familiar(CuTest *tc) {
unit *mag, *fam; unit *mag, *fam;
region *r; region *r;
@ -267,6 +292,29 @@ static void test_skill_familiar(CuTest *tc) {
test_cleanup(); 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 *get_unit_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); 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_remove_empty_units_in_region);
SUITE_ADD_TEST(suite, test_names); SUITE_ADD_TEST(suite, test_names);
SUITE_ADD_TEST(suite, test_default_name); 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_skill_familiar);
SUITE_ADD_TEST(suite, test_age_familiar);
return suite; return suite;
} }

View file

@ -256,7 +256,7 @@ int a_age(attrib ** p)
if (a->type->age) { if (a->type->age) {
int result = a->type->age(a); int result = a->type->age(a);
assert(result >= 0 || !"age() returned a negative value"); assert(result >= 0 || !"age() returned a negative value");
if (result == 0) { if (result == AT_AGE_REMOVE) {
a_remove(p, a); a_remove(p, a);
continue; continue;
} }

View file

@ -90,8 +90,8 @@ extern "C" {
#define AT_READ_OK 0 #define AT_READ_OK 0
#define AT_READ_FAIL -1 #define AT_READ_FAIL -1
#define AT_AGE_KEEP 0 /* keep the attribute for another turn */ #define AT_AGE_REMOVE 0 /* remove the attribute after calling age() */
#define AT_AGE_REMOVE 1 /* remove the attribute after calling age() */ #define AT_AGE_KEEP 1 /* keep the attribute for another turn */
#ifdef __cplusplus #ifdef __cplusplus
} }