From 4f2d9260d16aefe839ddee7a138a7bc90c992d62 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 13 Jan 2015 07:43:30 +0100 Subject: [PATCH] add a message to the unit that gets kicked, with tests --- res/core/messages.xml | 18 ++++++++++++++++++ src/laws.c | 6 ++++++ src/laws.test.c | 7 +++++++ src/tests.c | 9 +++++++++ src/tests.h | 2 ++ 5 files changed, 42 insertions(+) diff --git a/res/core/messages.xml b/res/core/messages.xml index 52b132220..cbc5dd780 100644 --- a/res/core/messages.xml +++ b/res/core/messages.xml @@ -1,5 +1,23 @@ + + + + + + + $unit($owner) bittet $unit($unit), $ship($ship) zu verlassen. + $unit($owner) asks $unit($unit) to leave $ship($ship). + + + + + + + + $unit($owner) bittet $unit($unit), $building($building) zu verlassen. + $unit($owner) asks $unit($unit) to leave $building($building). + diff --git a/src/laws.c b/src/laws.c index 5d51eeba4..ca80a9fb4 100755 --- a/src/laws.c +++ b/src/laws.c @@ -4277,14 +4277,20 @@ void force_leave(region *r) { unit *u; for (u = r->units; u; u = u->next) { unit *uo = NULL; + message *msg = NULL; if (u->building) { uo = building_owner(u->building); + msg = msg_message("force_leave_building", "unit owner building", u, uo, u->building); } if (u->ship && r->land) { uo = ship_owner(u->ship); + msg = msg_message("force_leave_ship", "unit owner ship", u, uo, u->ship); } if (uo && !help_enter(uo, u)) { leave(u, false); + if (msg) { + ADDMSG(&u->faction->msgs, msg); + } } } } diff --git a/src/laws.test.c b/src/laws.test.c index 14e6bb6c7..2b2f0bb9f 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -231,6 +232,7 @@ static void test_force_leave_buildings(CuTest *tc) { region *r; unit *u1, *u2, *u3; building * b; + message *msg; test_cleanup(); r = test_create_region(0, 0, test_create_terrain("plain", LAND_REGION)); u1 = test_create_unit(test_create_faction(NULL), r); @@ -245,6 +247,8 @@ static void test_force_leave_buildings(CuTest *tc) { CuAssertPtrEquals_Msg(tc, "owner should not be forecd to leave", b, u1->building); CuAssertPtrEquals_Msg(tc, "same faction should not be forced to leave", b, u2->building); CuAssertPtrEquals_Msg(tc, "non-allies should be forced to leave", NULL, u3->building); + msg = test_get_last_message(u3->faction->msgs); + CuAssertStrEquals(tc, "force_leave_building", test_get_messagetype(msg)); u_set_building(u3, b); al = ally_add(&u1->faction->allies, u3->faction); @@ -258,6 +262,7 @@ static void test_force_leave_ships(CuTest *tc) { region *r; unit *u1, *u2; ship *sh; + message *msg; test_cleanup(); r = test_create_region(0, 0, test_create_terrain("plain", LAND_REGION)); u1 = test_create_unit(test_create_faction(NULL), r); @@ -268,6 +273,8 @@ static void test_force_leave_ships(CuTest *tc) { ship_set_owner(u1); force_leave(r); CuAssertPtrEquals_Msg(tc, "non-allies should be forced to leave", NULL, u2->ship); + msg = test_get_last_message(u2->faction->msgs); + CuAssertStrEquals(tc, "force_leave_ship", test_get_messagetype(msg)); test_cleanup(); } diff --git a/src/tests.c b/src/tests.c index 4e5c41255..83c6fe6fa 100644 --- a/src/tests.c +++ b/src/tests.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -193,6 +194,14 @@ void test_create_world(void) test_create_shiptype("boat"); } +message * test_get_last_message(message_list *msgs) { + struct mlist *iter = msgs->begin; + while (iter->next) { + iter = iter->next; + } + return iter->msg; +} + const char * test_get_messagetype(const message *msg) { const char * name = msg->type->name; if (strcmp(name, "missing_message") == 0) { diff --git a/src/tests.h b/src/tests.h index 1780e4e74..b83beab40 100644 --- a/src/tests.h +++ b/src/tests.h @@ -14,6 +14,7 @@ extern "C" { struct building; struct ship; struct message; + struct message_list; struct item_type; struct building_type; struct ship_type; @@ -37,6 +38,7 @@ extern "C" { int RunAllTests(void); void test_translate_param(const struct locale *lang, param_t param, const char *text); const char * test_get_messagetype(const struct message *msg); + struct message * test_get_last_message(struct message_list *mlist); #ifdef __cplusplus }