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; return f;
} }
void change_locale(faction *f, const struct locale *lang) { void change_locale(faction *f, const struct locale *lang, bool del ) {
unit *ux; unit *ux;
for (ux = f->units; ux; ux = ux->nextF) { 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) { if (ux->old_orders) {
translate_orders(ux, lang, &ux->old_orders); translate_orders(ux, lang, &ux->old_orders, del);
} }
if (ux->thisorder) { if (ux->thisorder) {
translate_orders(ux, lang, &ux->thisorder); translate_orders(ux, lang, &ux->thisorder, del);
} }
} }
f->locale = lang; f->locale = lang;

View File

@ -155,7 +155,7 @@ extern "C" {
int count_migrants(const struct faction * f); int count_migrants(const struct faction * f);
int count_maxmigrants(const struct faction * f); int count_maxmigrants(const struct faction * f);
int max_magicians(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 #define MONSTER_ID 666
struct faction *getfaction(void); 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])); unit_addorder(u, ord = create_order(K_STUDY, f->locale, skillnames[SK_ENTERTAINMENT]));
CuAssertIntEquals(tc, SK_ENTERTAINMENT - 100, ord->id); CuAssertIntEquals(tc, SK_ENTERTAINMENT - 100, ord->id);
change_locale(f, lang); change_locale(f, lang, true);
CuAssertPtrEquals(tc, lang, (void *)f->locale); CuAssertPtrEquals(tc, lang, (void *)f->locale);
CuAssertPtrNotNull(tc, u->thisorder); CuAssertPtrNotNull(tc, u->thisorder);

View File

@ -1849,19 +1849,17 @@ 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 translate_orders(unit *u, const struct locale *lang, order **list)
{ {
order **po = list; (void)to_lang;
(void)lang; (void)from_lang;
while (*po) {
order *ord = *po;
if (ord->id <= 0) { if (ord->id <= 0) {
/* we can keep these, they have no problematic arguments */ /* no arguments, no translation needed */
po = &ord->next; return true;
continue;
} }
switch (getkeyword(ord)) { switch (getkeyword(ord)) {
case NOKEYWORD:
case K_ATTACK: case K_ATTACK:
case K_BANNER: case K_BANNER:
case K_DRIVE: case K_DRIVE:
@ -1878,17 +1876,31 @@ void translate_orders(unit *u, const struct locale *lang, order **list)
case K_TEACH: case K_TEACH:
case K_TRANSPORT: case K_TRANSPORT:
case K_URSPRUNG: case K_URSPRUNG:
/* we can keep these, they need no translation */ /* we can keep these, they do not use translated strings */
po = &ord->next; return true;
break; }
default:
/* we don't know what to do with these, drop them */ 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) { if (u->thisorder == ord) {
u->thisorder = NULL; u->thisorder = NULL;
} }
*po = ord->next; *po = ord->next;
ord->next = NULL; ord->next = NULL;
free_order(ord); free_order(ord);
continue;
} }
} }
po = &ord->next;
}
} }

View File

@ -223,7 +223,7 @@ extern "C" {
bool unit_name_equals_race(const struct unit *u); bool unit_name_equals_race(const struct unit *u);
void unit_convert_race(struct unit *u, const struct race *rc, const char *rcname); 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: */ /* getunit results: */
#define GET_UNIT 0 #define GET_UNIT 0

View File

@ -4225,13 +4225,14 @@ int locale_cmd(unit * u, order * ord)
char token[128]; char token[128];
const char * name; const char * name;
faction *f = u->faction; faction *f = u->faction;
bool del = config_get_int("translate.delete_orders", 0) != 0;
init_order(ord, f->locale); init_order(ord, f->locale);
name = gettoken(token, sizeof(token)); name = gettoken(token, sizeof(token));
if (name) { if (name) {
const struct locale *lang = get_locale(name); const struct locale *lang = get_locale(name);
if (lang && lang != f->locale) { if (lang && lang != f->locale) {
change_locale(f, lang); change_locale(f, lang, del);
} }
} }
return 0; return 0;