BENENNE REGION ist jeder Einheit des Regionsbesitzers erlaubt

This commit is contained in:
Enno Rehling 2017-01-25 20:57:54 +01:00 committed by Enno Rehling
parent 044953e4ab
commit 2a1ead6506
6 changed files with 47 additions and 28 deletions

View File

@ -496,15 +496,12 @@ static void test_building_type(CuTest *tc) {
static void test_cmp_castle_size(CuTest *tc) {
region *r;
building *b1, *b2;
building_type *bt_castle;
unit *u1, *u2;
test_setup();
bt_castle = test_create_buildingtype("castle");
bt_castle->protection = building_protection;
r = test_create_region(0, 0, 0);
b1 = test_create_building(r, bt_castle);
b2 = test_create_building(r, bt_castle);
b1 = test_create_building(r, NULL);
b2 = test_create_building(r, NULL);
u1 = test_create_unit(test_create_faction(0), r);
u_set_building(u1, b1);
u2 = test_create_unit(test_create_faction(0), r);

View File

@ -203,7 +203,7 @@ param_t findparam(const char *s, const struct locale * lang)
void **tokens = get_translations(lang, UT_PARAMS);
critbit_tree *cb = (critbit_tree *)*tokens;
if (!cb) {
log_error("no parameters defined in locale %s", locale_name(lang));
log_warning("no parameters defined in locale %s", locale_name(lang));
}
else if (cb_find_prefix(cb, str, strlen(str), &match, 1, 0)) {
cb_get_kv(match, &i, sizeof(int));

View File

@ -36,15 +36,12 @@ void test_terraform(CuTest *tc) {
static void test_region_get_owner(CuTest *tc) {
region *r;
building *b1, *b2;
building_type *bt_castle;
unit *u1, *u2;
test_setup();
bt_castle = test_create_buildingtype("castle");
bt_castle->protection = building_protection;
r = test_create_region(0, 0, 0);
b1 = test_create_building(r, bt_castle);
b2 = test_create_building(r, bt_castle);
b1 = test_create_building(r, NULL);
b2 = test_create_building(r, NULL);
b1->size = 5;
b2->size = 10;
u1 = test_create_unit(test_create_faction(0), r);

View File

@ -1892,16 +1892,7 @@ int name_cmd(struct unit *u, struct order *ord)
break;
case P_REGION:
if (!b) {
cmistake(u, ord, 145, MSG_EVENT);
break;
}
if (building_owner(b) != u) {
cmistake(u, ord, 148, MSG_EVENT);
break;
}
if (b != largestbuilding(r, get_cmp_region_owner(), false)) {
if (u->faction != region_get_owner(r)) {
cmistake(u, ord, 147, MSG_EVENT);
break;
}

View File

@ -812,10 +812,7 @@ static void test_name_region(CuTest *tc) {
f = u->faction;
ord = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_REGION]));
name_cmd(u, ord);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error145"));
u->building = test_create_building(u->region, 0);
u_set_building(u, test_create_building(u->region, 0));
name_cmd(u, ord);
CuAssertStrEquals(tc, "Hodor", u->region->land->name);
free_order(ord);
@ -1060,7 +1057,7 @@ static void test_name_cmd(CuTest *tc) {
free_order(ord);
ord = create_order(K_NAME, f->locale, "%s ' Ho\tdor '", LOC(f->locale, parameters[P_BUILDING]));
u->building = test_create_building(u->region, 0);
u_set_building(u, test_create_building(u->region, 0));
name_cmd(u, ord);
CuAssertStrEquals(tc, "Hodor", u->building->name);
free_order(ord);
@ -1073,6 +1070,37 @@ static void test_name_cmd(CuTest *tc) {
test_cleanup();
}
static void test_name_cmd_2274(CuTest *tc) {
unit *u1, *u2, *u3;
faction *f;
region *r;
test_setup();
r = test_create_region(0, 0, 0);
u1 = test_create_unit(test_create_faction(0), r);
u2 = test_create_unit(test_create_faction(0), r);
u3 = test_create_unit(u2->faction, r);
u_set_building(u1, test_create_building(r, NULL));
u1->building->size = 10;
u_set_building(u2, test_create_building(r, NULL));
u2->building->size = 20;
f = u2->faction;
u2->thisorder = create_order(K_NAME, f->locale, "%s Heimat", LOC(f->locale, parameters[P_REGION]));
name_cmd(u2, u2->thisorder);
CuAssertStrEquals(tc, "Heimat", r->land->name);
f = u3->faction;
u3->thisorder = create_order(K_NAME, f->locale, "%s Hodor", LOC(f->locale, parameters[P_REGION]));
name_cmd(u3, u3->thisorder);
CuAssertStrEquals(tc, "Hodor", r->land->name);
f = u1->faction;
u1->thisorder = create_order(K_NAME, f->locale, "%s notallowed", LOC(f->locale, parameters[P_REGION]));
name_cmd(u1, u1->thisorder);
CuAssertStrEquals(tc, "Hodor", r->land->name);
test_cleanup();
}
static void test_ally_cmd(CuTest *tc) {
unit *u;
faction * f;
@ -1481,6 +1509,7 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_nmr_warnings);
SUITE_ADD_TEST(suite, test_ally_cmd);
SUITE_ADD_TEST(suite, test_name_cmd);
SUITE_ADD_TEST(suite, test_name_cmd_2274);
SUITE_ADD_TEST(suite, test_ally_cmd_errors);
SUITE_ADD_TEST(suite, test_long_order_normal);
SUITE_ADD_TEST(suite, test_long_order_none);

View File

@ -225,8 +225,13 @@ building * test_create_building(region * r, const building_type * btype)
{
building * b;
assert(r);
b = new_building(btype ? btype : test_create_buildingtype("castle"), r, default_locale);
b->size = b->type->maxsize > 0 ? b->type->maxsize : 1;
if (!btype) {
building_type *bt_castle = test_create_buildingtype("castle");
bt_castle->protection = building_protection;
btype = bt_castle;
}
b = new_building(btype, r, default_locale);
b->size = btype->maxsize > 0 ? btype->maxsize : 1;
return b;
}