diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f32eafdc..9edf0b6bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - Bugfix für Schild des Fisches (Solthar) - Dämonen können magisch reanimiert werden. - "Schöne Träume" verliert seine Wirkung, wenn der Zauberer stirbt. + - Mit GIB 0 können hungernde Personen an die Bauern gegeben werden. # 3.27 diff --git a/src/give.c b/src/give.c index 8b2e5feb2..f84f838c5 100644 --- a/src/give.c +++ b/src/give.c @@ -265,7 +265,8 @@ static bool unit_has_cursed_item(const unit * u) return false; } -static bool can_give_men(const unit *u, const unit *dst, order *ord, message **msg) { +bool can_give_men(const unit *u, const unit *dst, order *ord, message **msg) +{ UNUSED_ARG(dst); if (unit_has_cursed_item(u)) { if (msg) *msg = msg_error(u, ord, 78); @@ -274,7 +275,7 @@ static bool can_give_men(const unit *u, const unit *dst, order *ord, message **m /* cannot give units to and from magicians */ if (msg) *msg = msg_error(u, ord, 158); } - else if (fval(u, UFL_HUNGER)) { + else if (dst && fval(u, UFL_HUNGER)) { /* hungry people cannot be given away */ if (msg) *msg = msg_error(u, ord, 73); } diff --git a/src/give.h b/src/give.h index 8c6fbaa52..b6940e6f6 100644 --- a/src/give.h +++ b/src/give.h @@ -24,6 +24,7 @@ extern "C" { enum param_t give_cmd(struct unit * u, struct order * ord); struct message * check_give(const struct unit * u, const struct unit * u2, struct order *ord); bool can_give_to(struct unit *u, struct unit *u2); + bool can_give_men(const struct unit *u, const struct unit *dst, struct order *ord, struct message **msg); bool rule_transfermen(void); #ifdef __cplusplus diff --git a/src/give.test.c b/src/give.test.c index cc356ce01..c1447a68f 100644 --- a/src/give.test.c +++ b/src/give.test.c @@ -72,6 +72,7 @@ static void setup_give(struct give *env) { mt_create_error(128); mt_create_error(129); mt_create_error(96); + mt_create_error(73); mt_create_error(10); mt_create_feedback("feedback_give_forbidden"); mt_create_feedback("peasants_give_invalid"); @@ -378,7 +379,8 @@ static void test_give_men_not_to_self(CuTest * tc) { struct give env = { 0 }; message * msg; test_setup_ex(tc); - env.f2 = env.f1 = test_create_faction(); + env.f1 = test_create_faction(); + env.f2 = NULL; setup_give(&env); msg = give_men(1, env.src, env.src, NULL); CuAssertStrEquals(tc, "error10", test_get_messagetype(msg)); @@ -387,13 +389,35 @@ static void test_give_men_not_to_self(CuTest * tc) { test_teardown(); } +static void test_give_men_hungry(CuTest * tc) { + struct give env = { 0 }; + message * msg = NULL; + test_setup_ex(tc); + env.f1 = test_create_faction(); + env.f2 = test_create_faction(); + setup_give(&env); + CuAssertTrue(tc, can_give_men(env.src, env.dst, NULL, &msg)); + CuAssertPtrEquals(tc, NULL, msg); + env.src->flags |= UFL_HUNGER; + CuAssertTrue(tc, !can_give_men(env.src, env.dst, NULL, &msg)); + CuAssertPtrNotNull(tc, msg); + CuAssertStrEquals(tc, "error73", test_get_messagetype(msg)); + msg_release(msg); + + msg = NULL; + CuAssertTrue(tc, can_give_men(env.src, NULL, NULL, &msg)); + CuAssertPtrEquals(tc, NULL, msg); + + test_teardown(); +} + static void test_give_peasants(CuTest * tc) { struct give env = { 0 }; message * msg; test_setup_ex(tc); env.f1 = test_create_faction(); - env.f2 = 0; + env.f2 = NULL; setup_give(&env); rsetpeasants(env.r, 0); msg = disband_men(1, env.src, NULL); @@ -553,6 +577,7 @@ CuSuite *get_give_suite(void) SUITE_ADD_TEST(suite, test_give_men_other_faction); SUITE_ADD_TEST(suite, test_give_men_requires_contact); SUITE_ADD_TEST(suite, test_give_men_not_to_self); + SUITE_ADD_TEST(suite, test_give_men_hungry); SUITE_ADD_TEST(suite, test_give_unit); SUITE_ADD_TEST(suite, test_give_unit_humans); SUITE_ADD_TEST(suite, test_give_unit_other_race);