From 62c68f0fdebd5ee0d1b0618cb87076b52b0a165e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=82awomir=20Lach?= Date: Mon, 28 Feb 2022 16:20:45 +0100 Subject: [PATCH] - Translation support for counters added Change char * type of counter name onto struct name_translation and set each city's counter name to Owned diff --git a/common/counters.c b/common/counters.c index 5bbe8076e1..6688703df2 100644 --- a/common/counters.c +++ b/common/counters.c @@ -25,7 +25,7 @@ static struct counter counters[MAX_COUNTERS] = { - { "Owned", COUNTER_OWNED, CTGT_CITY, 0 } + { (struct name_translation) NAME_INIT, COUNTER_OWNED, CTGT_CITY, 0 } }; static struct counter *counters_city[MAX_COUNTERS]; @@ -40,11 +40,14 @@ void counters_init(void) number_city_counters = 0; + name_set(&counters[0].name, NULL, N_("?counter:Owned")); + for (i = 0; i < MAX_COUNTERS; i++) { if (counters[i].type == COUNTER_OWNED) { /* City counter type */ counters_city[number_city_counters] = &counters[i]; + counters[i].index = number_city_counters; counters[i].target = CTGT_CITY; number_city_counters++; @@ -99,7 +102,28 @@ struct counter *counter_by_rule_name(const char *name) for (i = 0; i < MAX_COUNTERS; i++) { - if (0 == fc_strcasecmp(name, counters[i].rule_name)) + if (0 == fc_strcasecmp(name, counter_rule_name(&counters[i]))) + { + return &counters[i]; + } + } + + return NULL; +} +/************************************************************************//** + Search for counter by translated name + (return matched counter if found or NULL) +****************************************************************************/ +struct counter *counter_by_translated_name(const char *name) +{ + int i; + fc_assert_ret_val(NULL != name, NULL); + fc_assert_ret_val('\0' != name[0], NULL); + + for (i = 0; i < MAX_COUNTERS; i++) + { + if (0 == fc_strcasecmp(name, + counter_name_translation(&counters[i]))) { return &counters[i]; } @@ -107,6 +131,14 @@ struct counter *counter_by_rule_name(const char *name) return NULL; } +/************************************************************************//** + Returns translated name of given counter +****************************************************************************/ + +const char *counter_name_translation(const struct counter *counter) +{ + return name_translation_get(&counter->name); +} /************************************************************************//** Return rule name of a given counter @@ -114,7 +146,7 @@ struct counter *counter_by_rule_name(const char *name) const char *counter_rule_name(struct counter *pcount) { fc_assert_ret_val(NULL != pcount, NULL); - return pcount->rule_name; + return rule_name_get(&pcount->name); } /************************************************************************//** diff --git a/common/counters.h b/common/counters.h index b7d3d4aabd..62fd8e6ab7 100644 --- a/common/counters.h +++ b/common/counters.h @@ -17,6 +17,10 @@ extern "C" { #endif /* __cplusplus */ +/* common */ + +#include "name_translation.h" + enum counter_type { COUNTER_OWNED = 0, COUNTER_COUNT }; enum counter_target { CTGT_CITY }; @@ -26,7 +30,7 @@ enum counter_target { CTGT_CITY }; struct counter { - const char *rule_name; + struct name_translation name; enum counter_type type; enum counter_target target; int def; /* default value for each entity of given type @@ -44,6 +48,9 @@ int counter_id(struct counter *pcount); struct counter *counter_by_rule_name(const char *name); const char *counter_rule_name(struct counter *pcount); +const char *counter_name_translation(const struct counter *counter); +struct counter *counter_by_translated_name(const char *name); + int counter_index(struct counter *pcount); struct counter *counter_by_index(int index, enum counter_target target); int counters_get_city_counters_count(void); diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index 1e42f769b4..c9d12b5857 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -2649,7 +2649,7 @@ static void sg_save_counters(struct savedata *saving) "savefile.city_counters_order_size"); for (j = 0; j < count; j++) { - countnames[j] = counter_by_index(j, CTGT_CITY)->rule_name; + countnames[j] = counter_rule_name(counter_by_index(j, CTGT_CITY)); } secfile_insert_str_vec(saving->file, countnames, count, -- 2.35.1