Merge pull request #759 from ennorehling/master

Hotfix turn 1060, broken data from bug 2413
This commit is contained in:
Enno Rehling 2018-01-21 10:58:28 +01:00 committed by GitHub
commit 44f8e1909f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 5 deletions

View File

@ -1149,7 +1149,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);
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

@ -49,6 +49,37 @@ static void test_renumber_faction_duplicate(CuTest *tc) {
test_cleanup();
}
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;
@ -230,5 +261,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;
}