Merge pull request #871 from ennorehling/develop

BENENNE FREMDE und pathfinding
This commit is contained in:
Enno Rehling 2019-08-27 22:25:47 +02:00 committed by GitHub
commit 7eb1e59d5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 52 deletions

View File

@ -196,7 +196,6 @@ void register_attributes(void)
at_register(&at_group); at_register(&at_group);
at_register(&at_building_generic_type); at_register(&at_building_generic_type);
at_register(&at_npcfaction);
/* connection-typen */ /* connection-typen */
register_bordertype(&bt_noway); register_bordertype(&bt_noway);
@ -205,6 +204,7 @@ void register_attributes(void)
register_bordertype(&bt_illusionwall); register_bordertype(&bt_illusionwall);
register_bordertype(&bt_road); register_bordertype(&bt_road);
at_deprecate("npcfaction", a_readint);
at_deprecate("siege", a_readint); at_deprecate("siege", a_readint);
at_deprecate("maxmagicians", a_readint); /* factions with differnt magician limits, probably unused */ at_deprecate("maxmagicians", a_readint); /* factions with differnt magician limits, probably unused */
at_deprecate("hurting", a_readint); /* an old arena attribute */ at_deprecate("hurting", a_readint); /* an old arena attribute */

View File

@ -215,22 +215,6 @@ autoalliance(const faction * sf, const faction * f2)
return 0; return 0;
} }
static void init_npcfaction(variant *var)
{
var->i = 1;
}
attrib_type at_npcfaction = {
"npcfaction",
init_npcfaction,
NULL,
NULL,
a_writeint,
a_readint,
NULL,
ATF_UNIQUE
};
/** Limits the available help modes /** Limits the available help modes
* The bitfield returned by this function specifies the available help modes * The bitfield returned by this function specifies the available help modes
* in this game (so you can, for example, disable HELP GIVE globally). * in this game (so you can, for example, disable HELP GIVE globally).
@ -284,12 +268,6 @@ int alliance_status(const faction *f, const faction *f2, int status) {
if (status > 0) { if (status > 0) {
int mask = AllianceRestricted(); int mask = AllianceRestricted();
if (mask) { if (mask) {
if (a_find(f->attribs, &at_npcfaction)) {
return status;
}
if (a_find(f2->attribs, &at_npcfaction)) {
return status;
}
if (f->alliance != f2->alliance) { if (f->alliance != f2->alliance) {
status &= ~mask; status &= ~mask;
} }

View File

@ -141,11 +141,10 @@ static region **internal_path_find(region * handle_start, const region * target,
int maxlen, bool(*allowed) (const region *, const region *)) int maxlen, bool(*allowed) (const region *, const region *))
{ {
static region *path[MAXDEPTH + 2]; /* STATIC_RETURN: used for return, not across calls */ 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 *root = new_node(handle_start, 0, NULL);
node **handle_end = &root->next; node **handle_end = &root->next;
node *n = root; node *n = root;
bool found = false;
assert(maxlen <= MAXDEPTH); assert(maxlen <= MAXDEPTH);
fset(handle_start, RF_MARK); fset(handle_start, RF_MARK);
@ -156,12 +155,7 @@ static region **internal_path_find(region * handle_start, const region * target,
break; break;
for (d = 0; d != MAXDIRECTIONS; ++d) { for (d = 0; d != MAXDIRECTIONS; ++d) {
region *rn = rconnect(r, d); region *rn = rconnect(r, d);
if (rn == NULL) if (rn && !fval(rn, RF_MARK) && allowed(r, rn)) {
continue;
if (fval(rn, RF_MARK))
continue; /* already been there */
if (!allowed(r, rn))
continue; /* can't go there */
if (rn == target) { if (rn == target) {
int i = depth; int i = depth;
path[i + 1] = NULL; path[i + 1] = NULL;
@ -170,7 +164,6 @@ static region **internal_path_find(region * handle_start, const region * target,
path[--i] = n->r; path[--i] = n->r;
n = n->prev; n = n->prev;
} }
found = true;
break; break;
} }
else { else {
@ -179,13 +172,16 @@ static region **internal_path_find(region * handle_start, const region * target,
handle_end = &(*handle_end)->next; handle_end = &(*handle_end)->next;
} }
} }
if (found) }
if (d != MAXDIRECTIONS) {
break; break;
}
n = n->next; n = n->next;
} }
free_nodes(root); free_nodes(root);
if (found) if (d != MAXDIRECTIONS) {
return path; return path;
}
return NULL; 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) { 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); bool foreign = !(owner && owner->faction == u->faction);
if (!b) { if (!b) {
@ -1732,12 +1732,12 @@ static bool try_rename(unit *u, building *b, order *ord) {
msg_message("renamed_building_notseen", msg_message("renamed_building_notseen",
"building region", b, u->region)); "building region", b, u->region));
} }
if (owner != u) { }
}
if (owner && owner->faction != u->faction) {
cmistake(u, ord, 148, MSG_PRODUCE); cmistake(u, ord, 148, MSG_PRODUCE);
return false; return false;
} }
}
}
return true; return true;
} }

View File

@ -1355,6 +1355,24 @@ static void test_name_cmd(CuTest *tc) {
test_teardown(); 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) { static void test_name_cmd_2274(CuTest *tc) {
unit *u1, *u2, *u3; unit *u1, *u2, *u3;
faction *f; faction *f;
@ -2155,6 +2173,7 @@ CuSuite *get_laws_suite(void)
SUITE_ADD_TEST(suite, test_nmr_warnings); SUITE_ADD_TEST(suite, test_nmr_warnings);
SUITE_ADD_TEST(suite, test_ally_cmd); SUITE_ADD_TEST(suite, test_ally_cmd);
SUITE_ADD_TEST(suite, test_name_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_banner_cmd);
SUITE_ADD_TEST(suite, test_email_cmd); SUITE_ADD_TEST(suite, test_email_cmd);
SUITE_ADD_TEST(suite, test_name_cmd_2274); SUITE_ADD_TEST(suite, test_name_cmd_2274);