From 1ea8c80845895c007cf8b7115484b6b269d3c5fc Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 26 Oct 2016 17:51:24 +0200 Subject: [PATCH] test that is_guard changes when armedmen does. --- src/guard.c | 14 ++++++++++++++ src/guard.test.c | 27 +++++++++++++++++++++++++++ src/laws.c | 14 -------------- src/laws.h | 1 - 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/guard.c b/src/guard.c index 6f61cc599..cefcdb925 100644 --- a/src/guard.c +++ b/src/guard.c @@ -45,6 +45,20 @@ attrib_type at_guard = { ATF_UNIQUE }; +guard_t can_start_guarding(const unit * u) +{ + if (u->status >= ST_FLEE || fval(u, UFL_FLEEING)) + return E_GUARD_FLEEING; + /* 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; + if (IsImmune(u->faction)) + return E_GUARD_NEWBIE; + return E_GUARD_OK; +} + void update_guards(void) { const region *r; diff --git a/src/guard.test.c b/src/guard.test.c index f9c78e7c1..262631a30 100644 --- a/src/guard.test.c +++ b/src/guard.test.c @@ -1,6 +1,7 @@ #include #include "guard.h" +#include "laws.h" #include "monster.h" #include @@ -54,6 +55,31 @@ static void test_guard_armed(CuTest * tc) test_cleanup(); } +static void test_is_guard(CuTest * tc) +{ + unit *ug; + region *r; + item_type *itype; + + test_setup(); + itype = it_get_or_create(rt_get_or_create("sword")); + new_weapontype(itype, 0, 0.0, NULL, 0, 0, 0, SK_MELEE, 2); + r = test_create_region(0, 0, 0); + ug = test_create_unit(test_create_faction(0), r); + i_change(&ug->items, itype, 1); + set_level(ug, SK_MELEE, 2); + setguard(ug, GUARD_ALL); + CuAssertIntEquals(tc, 1, armedmen(ug, false)); + CuAssertTrue(tc, is_guard(ug, GUARD_RECRUIT)); + set_level(ug, SK_MELEE, 1); + CuAssertIntEquals(tc, 0, armedmen(ug, false)); + CuAssertTrue(tc, !is_guard(ug, GUARD_RECRUIT)); + set_level(ug, SK_MELEE, 2); + CuAssertIntEquals(tc, 1, armedmen(ug, false)); + CuAssertTrue(tc, is_guard(ug, GUARD_RECRUIT)); + test_cleanup(); +} + static void test_guard_unarmed(CuTest * tc) { unit *u, *ug; @@ -88,6 +114,7 @@ static void test_guard_monsters(CuTest * tc) CuSuite *get_guard_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_is_guard); SUITE_ADD_TEST(suite, test_guard_unskilled); SUITE_ADD_TEST(suite, test_guard_armed); SUITE_ADD_TEST(suite, test_guard_unarmed); diff --git a/src/laws.c b/src/laws.c index bd0ae7b92..a2f7f0044 100755 --- a/src/laws.c +++ b/src/laws.c @@ -2671,20 +2671,6 @@ int combatspell_cmd(unit * u, struct order *ord) return 0; } -guard_t can_start_guarding(const unit * u) -{ - if (u->status >= ST_FLEE || fval(u, UFL_FLEEING)) - return E_GUARD_FLEEING; - /* 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; - if (IsImmune(u->faction)) - return E_GUARD_NEWBIE; - return E_GUARD_OK; -} - int guard_on_cmd(unit * u, struct order *ord) { assert(getkeyword(ord) == K_GUARD); diff --git a/src/laws.h b/src/laws.h index 6c8633536..55020dc06 100755 --- a/src/laws.h +++ b/src/laws.h @@ -112,7 +112,6 @@ extern "C" { #define FORCE_LEAVE_ALL 2 bool rule_force_leave(int flag); bool help_enter(struct unit *uo, struct unit *u); - guard_t can_start_guarding(const struct unit * u); #ifdef __cplusplus }