From 366035510c0912ea2911accabab97b122667ed51 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 17 Aug 2010 22:32:36 -0700 Subject: [PATCH] fixing building renaming http://bugs.eressea.de/view.php?id=1798 foreign/owned was swapped --- src/gamecode/laws.c | 2 +- src/gamecode/laws_test.c | 27 +++++++++++++++++++++++++++ src/tests.c | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/gamecode/laws.c b/src/gamecode/laws.c index 4c755a544..515da34d3 100644 --- a/src/gamecode/laws.c +++ b/src/gamecode/laws.c @@ -1614,7 +1614,7 @@ rename_cmd(unit * u, order * ord, char **s, const char * s2) static int rename_building(unit * u, order * ord, building * b, const char * name) { unit * owner = b?building_owner(b):0; - boolean foreign = owner && owner->faction==u->faction; + boolean foreign = !(owner && owner->faction==u->faction); if (!b) { cmistake(u, ord, u->building?6:145, MSG_EVENT); diff --git a/src/gamecode/laws_test.c b/src/gamecode/laws_test.c index 281245153..c45719ec5 100644 --- a/src/gamecode/laws_test.c +++ b/src/gamecode/laws_test.c @@ -41,6 +41,32 @@ static void test_rename_building(CuTest * tc) { CuAssertStrEquals(tc, "Villa Nagel", b->name); } +static void test_rename_building_twice(CuTest * tc) { + region * r; + building * b; + unit * u; + faction * f; + building_type * btype; + + test_cleanup(); + test_create_world(); + + btype = bt_find("castle"); + + r = findregion(-1, 0); + b = new_building(btype, r, default_locale); + f = test_create_faction(rc_find("human")); + u = test_create_unit(f, r); + u->building = b; + fset(u, UFL_OWNER); + + rename_building(u, NULL, b, "Villa Nagel"); + CuAssertStrEquals(tc, "Villa Nagel", b->name); + + rename_building(u, NULL, b, "Villa Kunterbunt"); + CuAssertStrEquals(tc, "Villa Kunterbunt", b->name); +} + static void test_fishing_feeds_2_people(CuTest * tc) { region * r; faction * f; @@ -165,6 +191,7 @@ CuSuite* get_laws_suite(void) CuSuite* suite = CuSuiteNew(); SUITE_ADD_TEST(suite, &test_new_building_can_be_renamed); SUITE_ADD_TEST(suite, &test_rename_building); + SUITE_ADD_TEST(suite, &test_rename_building_twice); SUITE_ADD_TEST(suite, &test_fishing_feeds_2_people); SUITE_ADD_TEST(suite, &test_fishing_does_not_give_goblins_money); SUITE_ADD_TEST(suite, &test_fishing_gets_reset); diff --git a/src/tests.c b/src/tests.c index 27f28b791..e47442a22 100644 --- a/src/tests.c +++ b/src/tests.c @@ -116,6 +116,7 @@ void test_create_world(void) rc_human->maintenance = 10; btype = calloc(sizeof(building_type), 1); + btype->flags = BTF_NAMECHANGE; btype->_name = strdup("castle"); bt_register(btype);