diff --git a/src/guard.c b/src/guard.c index a7fa1a97a..55f189b6c 100644 --- a/src/guard.c +++ b/src/guard.c @@ -24,17 +24,18 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "monsters.h" #include -#include +#include #include #include #include -#include +#include +#include #include guard_t can_start_guarding(const unit * u) { - if (!u->region->land) { + if (u->region->terrain->flags & SEA_REGION) { return E_GUARD_TERRAIN; } if (u->status >= ST_FLEE || fval(u, UFL_FLEEING)) @@ -72,7 +73,6 @@ void setguard(unit * u, bool enabled) } else { assert(!fval(u, UFL_MOVED)); assert(u->status < ST_FLEE); - assert(u->region->land); fset(u, UFL_GUARD); fset(u->region, RF_GUARDED); } diff --git a/src/guard.test.c b/src/guard.test.c index cc59af4d8..8302bcc9a 100644 --- a/src/guard.test.c +++ b/src/guard.test.c @@ -140,7 +140,7 @@ static void test_update_guard(CuTest * tc) test_setup(); t_ocean = test_create_terrain("ocean", SEA_REGION); - t_plain = test_create_terrain("plain", LAND_REGION); + t_plain = test_create_terrain("packice", ARCTIC_REGION); itype = it_get_or_create(rt_get_or_create("sword")); new_weapontype(itype, 0, frac_zero, NULL, 0, 0, 0, SK_MELEE, 2); r = test_create_region(0, 0, t_plain); @@ -181,6 +181,13 @@ static void test_guard_on(CuTest * tc) guard_on_cmd(ug, ug->thisorder); CuAssertTrue(tc, is_guard(ug)); + terraform_region(r, test_create_terrain("packice", ARCTIC_REGION)); + + setguard(ug, false); + CuAssertIntEquals(tc, E_GUARD_OK, can_start_guarding(ug)); + guard_on_cmd(ug, ug->thisorder); + CuAssertTrue(tc, is_guard(ug)); + terraform_region(r, t_ocean); setguard(ug, false); @@ -189,13 +196,6 @@ static void test_guard_on(CuTest * tc) CuAssertTrue(tc, !is_guard(ug)); CuAssertPtrNotNull(tc, test_find_messagetype(ug->faction->msgs, "error2")); - setguard(ug, false); - t_ocean->flags &= ~ SEA_REGION; - CuAssertIntEquals(tc, E_GUARD_TERRAIN, can_start_guarding(ug)); - guard_on_cmd(ug, ug->thisorder); - CuAssertTrue(tc, !is_guard(ug)); - CuAssertPtrNotNull(tc, test_find_messagetype(ug->faction->msgs, "error_onlandonly")); - terraform_region(r, t_plain); i_change(&ug->items, itype, -1); diff --git a/src/laws.c b/src/laws.c index dfbd163cb..3d996971b 100644 --- a/src/laws.c +++ b/src/laws.c @@ -2699,12 +2699,7 @@ int guard_on_cmd(unit * u, struct order *ord) setguard(u, true); } else if (err == E_GUARD_TERRAIN) { - if (fval(u->region->terrain, SEA_REGION)) { - cmistake(u, ord, 2, MSG_EVENT); - } - else { - ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", "")); - } + cmistake(u, ord, 2, MSG_EVENT); } else if (err == E_GUARD_UNARMED) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unit_unarmed", ""));