test that is_guard changes when armedmen does.

This commit is contained in:
Enno Rehling 2016-10-26 17:51:24 +02:00
parent 4487f4d3e1
commit 1ea8c80845
4 changed files with 41 additions and 15 deletions

View File

@ -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;

View File

@ -1,6 +1,7 @@
#include <platform.h>
#include "guard.h"
#include "laws.h"
#include "monster.h"
#include <kernel/config.h>
@ -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);

View File

@ -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);

View File

@ -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
}