broke several monster behaviors, fixed.

This commit is contained in:
Enno Rehling 2020-02-08 21:24:07 +01:00
parent 3771b88bc6
commit b1098f7838
4 changed files with 13 additions and 6 deletions

View File

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

View File

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

View File

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

View File

@ -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);
@ -107,10 +108,16 @@ static void test_monsters_attack_ocean(CuTest * tc)
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");