Merge branch 'release-3.7' into develop

This commit is contained in:
Enno Rehling 2015-11-12 18:11:21 +01:00
commit 5ef9b624ff
4 changed files with 38 additions and 14 deletions

View File

@ -662,3 +662,18 @@ void building_setregion(building * b, region * r)
b->region = r; b->region = r;
} }
bool in_safe_building(unit *u1, unit *u2) {
if (u1->building) {
building * b = inside_building(u1);
if (b->type->flags & BTF_FORTIFICATION) {
if (!u2->building) {
return true;
}
if (u2->building != b || b != inside_building(u2)) {
return true;
}
}
}
return false;
}

View File

@ -89,6 +89,7 @@ extern "C" {
int bt_effsize(const struct building_type *btype, int bt_effsize(const struct building_type *btype,
const struct building *b, int bsize); const struct building *b, int bsize);
bool in_safe_building(struct unit *u1, struct unit *u2);
/* buildingt => building_type /* buildingt => building_type
* Name => locale_string(name) * Name => locale_string(name)
* MaxGroesse => levels * MaxGroesse => levels

View File

@ -386,7 +386,7 @@ static void test_active_building(CuTest *tc) {
building *b; building *b;
test_cleanup(); test_cleanup();
b = test_create_building(test_create_region(0,0,0), 0); b = test_create_building(test_create_region(0, 0, 0), 0);
CuAssertIntEquals(tc, false, building_is_active(b)); CuAssertIntEquals(tc, false, building_is_active(b));
b->flags |= BLD_WORKING; b->flags |= BLD_WORKING;
CuAssertIntEquals(tc, true, building_is_active(b)); CuAssertIntEquals(tc, true, building_is_active(b));
@ -395,6 +395,26 @@ static void test_active_building(CuTest *tc) {
test_cleanup(); test_cleanup();
} }
static void test_safe_building(CuTest *tc) {
building_type *btype;
unit *u1, *u2;
test_cleanup();
btype = test_create_buildingtype("castle");
u1 = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
u2 = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0));
CuAssertIntEquals(tc, false, in_safe_building(u1, u2));
u1->building = test_create_building(u1->region, btype);
CuAssertIntEquals(tc, false, in_safe_building(u1, u2));
btype->flags |= BTF_FORTIFICATION;
CuAssertIntEquals(tc, true, in_safe_building(u1, u2));
u2->building = u1->building;
CuAssertIntEquals(tc, true, in_safe_building(u1, u2));
u1->building->size = 2;
CuAssertIntEquals(tc, false, in_safe_building(u1, u2));
test_cleanup();
}
CuSuite *get_building_suite(void) CuSuite *get_building_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
@ -410,5 +430,6 @@ CuSuite *get_building_suite(void)
SUITE_ADD_TEST(suite, test_buildingowner_goes_to_same_faction_after_leave); SUITE_ADD_TEST(suite, test_buildingowner_goes_to_same_faction_after_leave);
SUITE_ADD_TEST(suite, test_buildingowner_goes_to_empty_unit_after_leave); SUITE_ADD_TEST(suite, test_buildingowner_goes_to_empty_unit_after_leave);
SUITE_ADD_TEST(suite, test_active_building); SUITE_ADD_TEST(suite, test_active_building);
SUITE_ADD_TEST(suite, test_safe_building);
return suite; return suite;
} }

View File

@ -157,19 +157,6 @@ static order *monster_attack(unit * u, const unit * target)
return create_order(K_ATTACK, u->faction->locale, "%i", target->no); return create_order(K_ATTACK, u->faction->locale, "%i", target->no);
} }
static bool in_safe_building(unit *u1, unit *u2) {
if (u1->building && u2->building == u1->building) {
building * b = inside_building(u1);
if (u2->building) {
if (b != inside_building(u2)) return true;
}
if (b->type->flags & BTF_FORTIFICATION) {
return true;
}
}
return false;
}
static order *get_money_for_dragon(region * r, unit * u, int wanted) static order *get_money_for_dragon(region * r, unit * u, int wanted)
{ {
int n; int n;