diff --git a/src/kernel/config.c b/src/kernel/config.c index 8698fde51..9c26ad85a 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -919,6 +919,10 @@ static const char * parameter_key(int i) return parameters[i]; } +void init_parameters(struct locale *lang) { + init_translations(lang, UT_PARAMS, parameter_key, MAXPARAMS); +} + void init_terrains_translation(const struct locale *lang) { void **tokens; @@ -1009,7 +1013,7 @@ void init_locale(struct locale *lang) if (name) addtoken(tokens, name, var); } - init_translations(lang, UT_PARAMS, parameter_key, MAXPARAMS); + init_parameters(lang); init_options_translation(lang); init_terrains_translation(lang); diff --git a/src/kernel/config.h b/src/kernel/config.h index 5e7e77899..056de8f84 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -291,6 +291,7 @@ extern "C" { void set_default_order(int kwd); int entertainmoney(const struct region *r); + void init_parameters(struct locale *lang); void free_gamedata(void); diff --git a/src/kernel/messages.c b/src/kernel/messages.c index e0efdd04b..28625ff85 100644 --- a/src/kernel/messages.c +++ b/src/kernel/messages.c @@ -285,8 +285,9 @@ extern unsigned int new_hashstring(const char *s); void free_messagelist(message_list * msgs) { - struct mlist **mlistptr = &msgs->begin; - while (*mlistptr) { + struct mlist **mlistptr; + assert(msgs && msgs->begin); + for (mlistptr = &msgs->begin; *mlistptr;) { struct mlist *ml = *mlistptr; *mlistptr = ml->next; msg_release(ml->msg); diff --git a/src/laws.c b/src/laws.c index b9df102cd..3f68294fb 100755 --- a/src/laws.c +++ b/src/laws.c @@ -1347,10 +1347,12 @@ int ally_cmd(unit * u, struct order *ord) s = gettoken(token, sizeof(token)); - if (s && !s[0]) + if (!s || !s[0]) { keyword = P_ANY; - else + } + else { keyword = findparam(s, u->faction->locale); + } sfp = &u->faction->allies; if (fval(u, UFL_GROUP)) { diff --git a/src/laws.test.c b/src/laws.test.c index 12c2e8ecd..0c4881c85 100644 --- a/src/laws.test.c +++ b/src/laws.test.c @@ -1,6 +1,7 @@ #include #include "laws.h" #include "battle.h" +#include "monster.h" #include #include @@ -913,9 +914,71 @@ static void test_long_order_hungry(CuTest *tc) { test_cleanup(); } +static void test_ally_cmd_errors(CuTest *tc) { + unit *u; + int fid; + order *ord; + + test_cleanup(); + u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); + u->faction->locale = get_or_create_locale("de"); + fid = u->faction->no + 1; + CuAssertPtrEquals(tc, 0, findfaction(fid)); + + ord = create_order(K_ALLY, u->faction->locale, itoa36(fid)); + ally_cmd(u, ord); + CuAssertStrEquals(tc, "error66", test_get_messagetype(u->faction->msgs->begin->msg)); + free_order(ord); + + test_cleanup(); +} + +static void test_ally_cmd(CuTest *tc) { + unit *u; + faction * f; + order *ord; + struct locale *lang; + + test_cleanup(); + u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); + f = test_create_faction(0); + u->faction->locale = lang = get_or_create_locale("de"); + locale_setstring(lang, parameters[P_NOT], "NICHT"); + locale_setstring(lang, parameters[P_GUARD], "BEWACHE"); + init_parameters(lang); + + ord = create_order(K_ALLY, lang, "%s", itoa36(f->no)); + ally_cmd(u, ord); + CuAssertPtrEquals(tc, 0, u->faction->msgs); + CuAssertIntEquals(tc, HELP_ALL, alliedfaction(0, u->faction, f, HELP_ALL)); + free_order(ord); + + ord = create_order(K_ALLY, lang, "%s NICHT", itoa36(f->no)); + ally_cmd(u, ord); + CuAssertPtrEquals(tc, 0, u->faction->msgs); + CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL)); + free_order(ord); + + ord = create_order(K_ALLY, lang, "%s BEWACHE", itoa36(f->no)); + ally_cmd(u, ord); + CuAssertPtrEquals(tc, 0, u->faction->msgs); + CuAssertIntEquals(tc, HELP_GUARD, alliedfaction(0, u->faction, f, HELP_ALL)); + free_order(ord); + + ord = create_order(K_ALLY, lang, "%s BEWACHE NICHT", itoa36(f->no)); + ally_cmd(u, ord); + CuAssertPtrEquals(tc, 0, u->faction->msgs); + CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL)); + free_order(ord); + + test_cleanup(); +} + CuSuite *get_laws_suite(void) { CuSuite *suite = CuSuiteNew(); + SUITE_ADD_TEST(suite, test_ally_cmd); + SUITE_ADD_TEST(suite, test_ally_cmd_errors); SUITE_ADD_TEST(suite, test_long_order_normal); SUITE_ADD_TEST(suite, test_long_order_none); SUITE_ADD_TEST(suite, test_long_order_cast);