diff --git a/src/kernel/race.c b/src/kernel/race.c index 95239bd3f..23b25c891 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -294,7 +294,7 @@ static race *rc_find_i(const char *name) return rc; } -const race * rc_find(const char *name) { +race * rc_find(const char *name) { return rc_find_i(name); } diff --git a/src/kernel/race.h b/src/kernel/race.h index bce12912d..4cc07564e 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -155,7 +155,7 @@ extern "C" { race *rc_create(const char *zName); race *rc_get_or_create(const char *name); bool rc_changed(int *cache); - const race *rc_find(const char *); + race *rc_find(const char *); void free_races(void); bool rc_can_use(const struct race *rc, const struct item_type *itype); diff --git a/src/monsters.c b/src/monsters.c index a50c37e8a..08b65ce3a 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -794,9 +794,9 @@ void plan_monsters(faction * f) /* units with a plan to kill get ATTACK orders (even if they don't guard): */ ta = a_find(u->attribs, &at_hate); - if (ta && !monster_is_waiting(u) && monster_can_attack(u)) { + if (ta && !monster_is_waiting(u)) { unit *tu = (unit *)ta->data.v; - if (tu && tu->region == r) { + if (tu && tu->region == r && monster_can_attack(u)) { order * ord = monster_attack(u, tu); if (ord) { unit_addorder(u, ord); diff --git a/src/monsters.test.c b/src/monsters.test.c index 75a2cbc97..695e2f5e2 100644 --- a/src/monsters.test.c +++ b/src/monsters.test.c @@ -97,6 +97,7 @@ static void test_monsters_attack_ocean(CuTest * tc) { region *r; unit *u, *m; + race *rc; test_setup(); create_monsters(&u, &m); @@ -105,12 +106,18 @@ static void test_monsters_attack_ocean(CuTest * tc) unit_setid(u, 2); m = test_create_unit(m->faction, r); assert(!m->region->land); - + config_set("rules.monsters.attack_chance", "1"); + rc = rc_find(m->_race->_name); + freset(rc, RCF_SWIM); plan_monsters(m->faction); + CuAssertPtrEquals(tc, NULL, find_order("attack 2", m)); + fset(rc, RCF_SWIM); + plan_monsters(m->faction); CuAssertPtrNotNull(tc, find_order("attack 2", m)); + test_teardown(); } @@ -145,7 +152,7 @@ static void test_seaserpent_piracy(CuTest * tc) u_setrace(m, rc = test_create_race("seaserpent")); assert(!m->region->land); fset(m, UFL_MOVED); - fset(rc, RCF_ATTACK_MOVED); + fset(rc, RCF_ATTACK_MOVED|RCF_SWIM); config_set("rules.monsters.attack_chance", "1");