fix pathfinding

fix BENENNE FREMDE BURG
This commit is contained in:
Enno Rehling 2019-08-27 22:17:28 +02:00
parent c87944afad
commit aef98424ea
3 changed files with 26 additions and 7 deletions

View File

@ -141,7 +141,7 @@ static region **internal_path_find(region * handle_start, const region * target,
int maxlen, bool(*allowed) (const region *, const region *))
{
static region *path[MAXDEPTH + 2]; /* STATIC_RETURN: used for return, not across calls */
direction_t d;
direction_t d = MAXDIRECTIONS;
node *root = new_node(handle_start, 0, NULL);
node **handle_end = &root->next;
node *n = root;
@ -179,7 +179,7 @@ static region **internal_path_find(region * handle_start, const region * target,
n = n->next;
}
free_nodes(root);
if (n) {
if (d != MAXDIRECTIONS) {
return path;
}
return NULL;

View File

@ -1702,7 +1702,7 @@ static int rename_cmd(unit * u, order * ord, char **s, const char *s2)
}
static bool try_rename(unit *u, building *b, order *ord) {
unit *owner = b ? building_owner(b) : 0;
unit *owner = b ? building_owner(b) : NULL;
bool foreign = !(owner && owner->faction == u->faction);
if (!b) {
@ -1732,12 +1732,12 @@ static bool try_rename(unit *u, building *b, order *ord) {
msg_message("renamed_building_notseen",
"building region", b, u->region));
}
if (owner != u) {
cmistake(u, ord, 148, MSG_PRODUCE);
return false;
}
}
}
if (owner && owner->faction != u->faction) {
cmistake(u, ord, 148, MSG_PRODUCE);
return false;
}
return true;
}

View File

@ -1355,6 +1355,24 @@ static void test_name_cmd(CuTest *tc) {
test_teardown();
}
static void test_name_foreign_cmd(CuTest *tc) {
building *b;
faction *f;
region *r;
unit *u;
test_setup();
u = test_create_unit(f = test_create_faction(NULL), r = test_create_region(0, 0, NULL));
b = test_create_building(u->region, NULL);
u->thisorder = create_order(K_NAME, f->locale, "%s %s %s Hodor",
LOC(f->locale, parameters[P_FOREIGN]),
LOC(f->locale, parameters[P_BUILDING]),
itoa36(b->no));
name_cmd(u, u->thisorder);
CuAssertStrEquals(tc, "Hodor", b->name);
test_teardown();
}
static void test_name_cmd_2274(CuTest *tc) {
unit *u1, *u2, *u3;
faction *f;
@ -2155,6 +2173,7 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_nmr_warnings);
SUITE_ADD_TEST(suite, test_ally_cmd);
SUITE_ADD_TEST(suite, test_name_cmd);
SUITE_ADD_TEST(suite, test_name_foreign_cmd);
SUITE_ADD_TEST(suite, test_banner_cmd);
SUITE_ADD_TEST(suite, test_email_cmd);
SUITE_ADD_TEST(suite, test_name_cmd_2274);