Merge branch 'master' into develop

This commit is contained in:
Enno Rehling 2018-01-21 11:01:05 +01:00
commit c1bacdb5fd
3 changed files with 42 additions and 5 deletions

View File

@ -1076,7 +1076,8 @@ void write_faction(gamedata *data, const faction * f)
ursprung *ur;
assert(f->_alive);
write_faction_reference(f, data->store);
assert(f->no > 0 && f->no <= MAX_UNIT_NR);
WRITE_INT(data->store, f->no);
WRITE_INT(data->store, f->subscription);
#if RELEASE_VERSION >= SPELL_LEVEL_VERSION
WRITE_INT(data->store, f->max_spelllevel);

View File

@ -88,11 +88,15 @@ int renumber_cmd(unit * u, order * ord)
s = gettoken(token, sizeof(token));
if (s && *s) {
int id = atoi36((const char *)s);
attrib *a = a_find(f->attribs, &at_number);
if (!a)
a = a_add(&f->attribs, a_new(&at_number));
a->data.i = id;
if (id > 0 && id <= MAX_UNIT_NR) {
attrib *a = a_find(f->attribs, &at_number);
if (!a)
a = a_add(&f->attribs, a_new(&at_number));
a->data.i = id;
break;
}
}
cmistake(u, ord, 114, MSG_EVENT);
break;
case P_UNIT:

View File

@ -51,6 +51,37 @@ static void test_renumber_faction_duplicate(CuTest *tc) {
test_teardown();
}
static void test_renumber_faction_invalid(CuTest *tc) {
unit *u;
faction *f;
int no;
const struct locale *lang;
test_setup_ex(tc);
u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0));
no = f->no;
lang = f->locale;
u->thisorder = create_order(K_NUMBER, lang, "%s [halima]", LOC(lang, parameters[P_FACTION]));
renumber_cmd(u, u->thisorder);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error114"));
renumber_factions();
CuAssertIntEquals(tc, no, f->no);
test_clear_messages(f);
free_order(u->thisorder);
u->thisorder = create_order(K_NUMBER, lang, "%s 10000", LOC(lang, parameters[P_FACTION]));
renumber_cmd(u, u->thisorder);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error114"));
test_clear_messages(f);
free_order(u->thisorder);
u->thisorder = create_order(K_NUMBER, lang, "%s 0", LOC(lang, parameters[P_FACTION]));
renumber_cmd(u, u->thisorder);
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error114"));
test_cleanup();
}
static void test_renumber_building(CuTest *tc) {
unit *u;
int uno, no;
@ -232,5 +263,6 @@ CuSuite *get_renumber_suite(void)
SUITE_ADD_TEST(suite, test_renumber_ship_duplicate);
SUITE_ADD_TEST(suite, test_renumber_faction);
SUITE_ADD_TEST(suite, test_renumber_faction_duplicate);
SUITE_ADD_TEST(suite, test_renumber_faction_invalid);
return suite;
}