LOCALE command: do not delete orders with incomplete translations

Instead, we let the player fix them from echeck warnings.
This commit is contained in:
Enno Rehling 2020-08-12 15:39:16 +02:00
parent 7759f7840a
commit aa28ad323a
6 changed files with 54 additions and 41 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -1849,19 +1849,17 @@ void unit_convert_race(unit *u, const race *rc, const char *rcname)
}
}
void translate_orders(unit *u, const struct locale *lang, order **list)
bool translate_order(order *ord, const struct locale *from_lang, const struct locale *to_lang)
{
order **po = list;
(void)lang;
while (*po) {
order *ord = *po;
(void)to_lang;
(void)from_lang;
if (ord->id <= 0) {
/* we can keep these, they have no problematic arguments */
po = &ord->next;
continue;
/* no arguments, no translation needed */
return true;
}
switch (getkeyword(ord)) {
case NOKEYWORD:
case K_ATTACK:
case K_BANNER:
case K_DRIVE:
@ -1878,17 +1876,31 @@ void translate_orders(unit *u, const struct locale *lang, order **list)
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 */
/* 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 (!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;
}
}

View File

@ -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

View File

@ -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;