diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 03026a7bd..d31a9be1d 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -836,15 +836,15 @@ faction *faction_create(int no) return f; } -void change_locale(faction *f, const struct locale *lang) { +void change_locale(faction *f, const struct locale *lang, bool del ) { unit *ux; for (ux = f->units; ux; ux = ux->nextF) { - translate_orders(ux, lang, &ux->orders); + translate_orders(ux, lang, &ux->orders, del); if (ux->old_orders) { - translate_orders(ux, lang, &ux->old_orders); + translate_orders(ux, lang, &ux->old_orders, del); } if (ux->thisorder) { - translate_orders(ux, lang, &ux->thisorder); + translate_orders(ux, lang, &ux->thisorder, del); } } f->locale = lang; diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 94835c33e..537a745d0 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -155,7 +155,7 @@ extern "C" { int count_migrants(const struct faction * f); int count_maxmigrants(const struct faction * f); int max_magicians(const struct faction * f); - void change_locale(struct faction *f, const struct locale *lang); + void change_locale(struct faction *f, const struct locale *lang, bool del); #define MONSTER_ID 666 struct faction *getfaction(void); diff --git a/src/kernel/faction.test.c b/src/kernel/faction.test.c index 21b9b5fad..968e093af 100644 --- a/src/kernel/faction.test.c +++ b/src/kernel/faction.test.c @@ -167,7 +167,7 @@ static void test_change_locale(CuTest *tc) { unit_addorder(u, ord = create_order(K_STUDY, f->locale, skillnames[SK_ENTERTAINMENT])); CuAssertIntEquals(tc, SK_ENTERTAINMENT - 100, ord->id); - change_locale(f, lang); + change_locale(f, lang, true); CuAssertPtrEquals(tc, lang, (void *)f->locale); CuAssertPtrNotNull(tc, u->thisorder); diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 7b57f0059..494837d9d 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1849,46 +1849,58 @@ void unit_convert_race(unit *u, const race *rc, const char *rcname) } } +bool translate_order(order *ord, const struct locale *from_lang, const struct locale *to_lang) +{ + (void)to_lang; + (void)from_lang; -void translate_orders(unit *u, const struct locale *lang, order **list) + if (ord->id <= 0) { + /* no arguments, no translation needed */ + return true; + } + switch (getkeyword(ord)) { + case NOKEYWORD: + case K_ATTACK: + case K_BANNER: + case K_DRIVE: + case K_FOLLOW: + case K_GROUP: + case K_KOMMENTAR: + case K_MAIL: + case K_NUMBER: + case K_PASSWORD: + case K_PREFIX: + case K_RECRUIT: + case K_SPY: + case K_STEAL: + case K_TEACH: + case K_TRANSPORT: + case K_URSPRUNG: + /* we can keep these, they do not use translated strings */ + return true; + } + + return false; +} + +void translate_orders(unit *u, const struct locale *lang, order **list, bool del) { order **po = list; (void)lang; while (*po) { order *ord = *po; - if (ord->id <= 0) { - /* we can keep these, they have no problematic arguments */ - po = &ord->next; - continue; - } - switch (getkeyword(ord)) { - case K_ATTACK: - case K_BANNER: - case K_DRIVE: - case K_FOLLOW: - case K_GROUP: - case K_KOMMENTAR: - case K_MAIL: - case K_NUMBER: - case K_PASSWORD: - case K_PREFIX: - case K_RECRUIT: - case K_SPY: - case K_STEAL: - case K_TEACH: - case K_TRANSPORT: - case K_URSPRUNG: - /* we can keep these, they need no translation */ - po = &ord->next; - break; - default: - /* we don't know what to do with these, drop them */ - if (u->thisorder == ord) { - u->thisorder = NULL; + if (!translate_order(ord, u->faction->locale, lang)) { + /* we don't know what to do with these, drop or keep them? */ + if (del) { + if (u->thisorder == ord) { + u->thisorder = NULL; + } + *po = ord->next; + ord->next = NULL; + free_order(ord); + continue; } - *po = ord->next; - ord->next = NULL; - free_order(ord); } + po = &ord->next; } } diff --git a/src/kernel/unit.h b/src/kernel/unit.h index 934527db1..396d97ead 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -223,7 +223,7 @@ extern "C" { bool unit_name_equals_race(const struct unit *u); void unit_convert_race(struct unit *u, const struct race *rc, const char *rcname); - void translate_orders(struct unit *u, const struct locale *lang, struct order **list); + void translate_orders(struct unit *u, const struct locale *lang, struct order **list, bool del); /* getunit results: */ #define GET_UNIT 0 diff --git a/src/laws.c b/src/laws.c index 0d0a36091..b18a3dd2b 100644 --- a/src/laws.c +++ b/src/laws.c @@ -4225,13 +4225,14 @@ int locale_cmd(unit * u, order * ord) char token[128]; const char * name; faction *f = u->faction; + bool del = config_get_int("translate.delete_orders", 0) != 0; init_order(ord, f->locale); name = gettoken(token, sizeof(token)); if (name) { const struct locale *lang = get_locale(name); if (lang && lang != f->locale) { - change_locale(f, lang); + change_locale(f, lang, del); } } return 0;