Mit GIB 0 können hungernde Personen an die Bauern gegeben werden.

This commit is contained in:
Enno Rehling 2021-04-01 18:54:56 +02:00
parent d1bad6773c
commit bb12ffa2a2
4 changed files with 32 additions and 4 deletions

View File

@ -3,6 +3,7 @@
- Bugfix für Schild des Fisches (Solthar) - Bugfix für Schild des Fisches (Solthar)
- Dämonen können magisch reanimiert werden. - Dämonen können magisch reanimiert werden.
- "Schöne Träume" verliert seine Wirkung, wenn der Zauberer stirbt. - "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 # 3.27

View File

@ -265,7 +265,8 @@ static bool unit_has_cursed_item(const unit * u)
return false; 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); UNUSED_ARG(dst);
if (unit_has_cursed_item(u)) { if (unit_has_cursed_item(u)) {
if (msg) *msg = msg_error(u, ord, 78); 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 */ /* cannot give units to and from magicians */
if (msg) *msg = msg_error(u, ord, 158); 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 */ /* hungry people cannot be given away */
if (msg) *msg = msg_error(u, ord, 73); if (msg) *msg = msg_error(u, ord, 73);
} }

View File

@ -24,6 +24,7 @@ extern "C" {
enum param_t give_cmd(struct unit * u, struct order * ord); 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); 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_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); bool rule_transfermen(void);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -72,6 +72,7 @@ static void setup_give(struct give *env) {
mt_create_error(128); mt_create_error(128);
mt_create_error(129); mt_create_error(129);
mt_create_error(96); mt_create_error(96);
mt_create_error(73);
mt_create_error(10); mt_create_error(10);
mt_create_feedback("feedback_give_forbidden"); mt_create_feedback("feedback_give_forbidden");
mt_create_feedback("peasants_give_invalid"); mt_create_feedback("peasants_give_invalid");
@ -378,7 +379,8 @@ static void test_give_men_not_to_self(CuTest * tc) {
struct give env = { 0 }; struct give env = { 0 };
message * msg; message * msg;
test_setup_ex(tc); test_setup_ex(tc);
env.f2 = env.f1 = test_create_faction(); env.f1 = test_create_faction();
env.f2 = NULL;
setup_give(&env); setup_give(&env);
msg = give_men(1, env.src, env.src, NULL); msg = give_men(1, env.src, env.src, NULL);
CuAssertStrEquals(tc, "error10", test_get_messagetype(msg)); CuAssertStrEquals(tc, "error10", test_get_messagetype(msg));
@ -387,13 +389,35 @@ static void test_give_men_not_to_self(CuTest * tc) {
test_teardown(); 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) { static void test_give_peasants(CuTest * tc) {
struct give env = { 0 }; struct give env = { 0 };
message * msg; message * msg;
test_setup_ex(tc); test_setup_ex(tc);
env.f1 = test_create_faction(); env.f1 = test_create_faction();
env.f2 = 0; env.f2 = NULL;
setup_give(&env); setup_give(&env);
rsetpeasants(env.r, 0); rsetpeasants(env.r, 0);
msg = disband_men(1, env.src, NULL); 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_other_faction);
SUITE_ADD_TEST(suite, test_give_men_requires_contact); 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_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);
SUITE_ADD_TEST(suite, test_give_unit_humans); SUITE_ADD_TEST(suite, test_give_unit_humans);
SUITE_ADD_TEST(suite, test_give_unit_other_race); SUITE_ADD_TEST(suite, test_give_unit_other_race);