Monster bewachten nicht, wenn sie nicht ausreichend bewaffnet waren, weil der nötige Check nicht in can_start_guarding gemacht wurde, sondern in guard_on_cmd.
This commit is contained in:
Enno Rehling 2015-11-23 15:35:26 +01:00
parent c7ab0e8f59
commit b6a947ca0c
2 changed files with 29 additions and 20 deletions

View file

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

View file

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