From b6a947ca0c190d5827af13c9d6349060252f992b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 23 Nov 2015 15:35:26 +0100 Subject: [PATCH] =?UTF-8?q?https://bugs.eressea.de/view.php=3Fid=3D2165=20?= =?UTF-8?q?Monster=20bewachten=20nicht,=20wenn=20sie=20nicht=20ausreichend?= =?UTF-8?q?=20bewaffnet=20waren,=20weil=20der=20n=C3=B6tige=20Check=20nich?= =?UTF-8?q?t=20in=20can=5Fstart=5Fguarding=20gemacht=20wurde,=20sondern=20?= =?UTF-8?q?in=20guard=5Fon=5Fcmd.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/laws.c | 31 ++++++++++++------------------- src/laws.test.c | 18 +++++++++++++++++- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/laws.c b/src/laws.c index 15c5404b4..f508c4b69 100755 --- a/src/laws.c +++ b/src/laws.c @@ -2673,13 +2673,12 @@ int combatspell_cmd(unit * u, struct order *ord) return 0; } -/* Beachten: einige Monster sollen auch unbewaffent die Region bewachen -* können */ guard_t can_start_guarding(const unit * u) { if (u->status >= ST_FLEE || fval(u, UFL_FLEEING)) return E_GUARD_FLEEING; - if (fval(u_race(u), RCF_UNARMEDGUARD)) + /* Monster der Monsterpartei dürfen immer bewachen */ + if (is_monsters(u->faction) || fval(u_race(u), RCF_UNARMEDGUARD)) return E_GUARD_OK; if (!armedmen(u, true)) return E_GUARD_UNARMED; @@ -2713,24 +2712,18 @@ int guard_on_cmd(unit * u, struct order *ord) cmistake(u, ord, 95, MSG_EVENT); } else { - /* Monster der Monsterpartei dürfen immer bewachen */ - if (is_monsters(u->faction)) { + int err = can_start_guarding(u); + if (err == E_GUARD_OK) { guard(u, GUARD_ALL); } - else { - int err = can_start_guarding(u); - if (err == E_GUARD_OK) { - guard(u, GUARD_ALL); - } - else if (err == E_GUARD_UNARMED) { - ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unit_unarmed", "")); - } - else if (err == E_GUARD_FLEEING) { - cmistake(u, ord, 320, MSG_EVENT); - } - else if (err == E_GUARD_NEWBIE) { - cmistake(u, ord, 304, MSG_EVENT); - } + else if (err == E_GUARD_UNARMED) { + ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unit_unarmed", "")); + } + else if (err == E_GUARD_FLEEING) { + cmistake(u, ord, 320, MSG_EVENT); + } + else if (err == E_GUARD_NEWBIE) { + cmistake(u, ord, 304, MSG_EVENT); } } } diff --git a/src/laws.test.c b/src/laws.test.c index e829eff27..daa67eb86 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -635,6 +635,7 @@ static void test_newbie_cannot_guard(CuTest *tc) { setup_guard(&fix, true); set_param(&global.parameters, "NewbieImmunity", "4"); CuAssertTrue(tc, IsImmune(fix.u->faction)); + CuAssertIntEquals(tc, E_GUARD_NEWBIE, can_start_guarding(fix.u)); update_guards(); CuAssertTrue(tc, !fval(fix.u, UFL_GUARD)); test_cleanup(); @@ -644,6 +645,7 @@ static void test_unarmed_cannot_guard(CuTest *tc) { guard_fixture fix; setup_guard(&fix, false); + CuAssertIntEquals(tc, E_GUARD_UNARMED, can_start_guarding(fix.u)); update_guards(); CuAssertTrue(tc, !fval(fix.u, UFL_GUARD)); test_cleanup(); @@ -656,6 +658,18 @@ static void test_unarmed_races_can_guard(CuTest *tc) { setup_guard(&fix, false); rc = rc_get_or_create(fix.u->_race->_name); rc->flags |= RCF_UNARMEDGUARD; + CuAssertIntEquals(tc, E_GUARD_OK, can_start_guarding(fix.u)); + update_guards(); + CuAssertTrue(tc, fval(fix.u, UFL_GUARD)); + test_cleanup(); +} + +static void test_monsters_can_guard(CuTest *tc) { + guard_fixture fix; + + setup_guard(&fix, false); + u_setfaction(fix.u, get_or_create_monsters()); + CuAssertIntEquals(tc, E_GUARD_OK, can_start_guarding(fix.u)); update_guards(); CuAssertTrue(tc, fval(fix.u, UFL_GUARD)); test_cleanup(); @@ -666,7 +680,7 @@ static void test_low_skill_cannot_guard(CuTest *tc) { setup_guard(&fix, true); set_level(fix.u, SK_MELEE, 1); - fix.u->status = ST_FLEE; + CuAssertIntEquals(tc, E_GUARD_UNARMED, can_start_guarding(fix.u)); update_guards(); CuAssertTrue(tc, !fval(fix.u, UFL_GUARD)); test_cleanup(); @@ -677,6 +691,7 @@ static void test_fleeing_cannot_guard(CuTest *tc) { setup_guard(&fix, true); fix.u->status = ST_FLEE; + CuAssertIntEquals(tc, E_GUARD_FLEEING, can_start_guarding(fix.u)); update_guards(); CuAssertTrue(tc, !fval(fix.u, UFL_GUARD)); test_cleanup(); @@ -1269,6 +1284,7 @@ CuSuite *get_laws_suite(void) SUITE_ADD_TEST(suite, test_newbie_cannot_guard); SUITE_ADD_TEST(suite, test_unarmed_cannot_guard); SUITE_ADD_TEST(suite, test_unarmed_races_can_guard); + SUITE_ADD_TEST(suite, test_monsters_can_guard); SUITE_ADD_TEST(suite, test_fleeing_cannot_guard); SUITE_ADD_TEST(suite, test_low_skill_cannot_guard); SUITE_ADD_TEST(suite, test_reserve_self);