From aa449bd414573db2f07a31bdea6d4fe2ef0d8115 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 6 Feb 2022 07:10:48 +0200 Subject: [PATCH 45/45] Move unrelated functions out from featured_text.[ch] Move functions unrelated to featured text, and used only by unithand.c, as static functions to unithand.c See osdn #43380 Signed-off-by: Marko Lindqvist --- common/featured_text.c | 78 ---------------------------------------- common/featured_text.h | 4 --- server/unithand.c | 81 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 82 deletions(-) diff --git a/common/featured_text.c b/common/featured_text.c index 38602ca0b4..9cfb819882 100644 --- a/common/featured_text.c +++ b/common/featured_text.c @@ -1114,84 +1114,6 @@ const char *tile_link(const struct tile *ptile) return buf; } -/**********************************************************************//** - Get a text of a unit's vet level. - N.B.: The returned string is static, so every call to this function - overwrites the previous. -**************************************************************************/ -const char *unit_veteran_level_string(const struct unit *punit) -{ - static char buf[MAX_LEN_LINK]; - const struct veteran_level *vlevel; - - if (!punit) { - buf[0] = '\0'; /* If no unit, return empty string */ - return buf; - } - - vlevel = utype_veteran_level(unit_type_get(punit), punit->veteran); - fc_snprintf(buf, sizeof(buf), "%s", name_translation_get(&vlevel->name)); - return buf; -} - -/**********************************************************************//** - Get string of when unit gets upgraded to new veteran level. - N.B.: The returned string is static, so every call to this function - overwrites the previous. -**************************************************************************/ -const char *unit_achieved_rank_string(const struct unit *punit) -{ - static char buf[MAX_LEN_LINK]; - - fc_snprintf(buf, sizeof(buf), - /* TRANS: " and achieved the rank of "; - * preserve leading space */ - _(" and achieved the rank of %s"), - unit_veteran_level_string(punit)); - return buf; -} - -/**********************************************************************//** - Get string of unit's attack would be a tired attack or not. - N.B.: The returned string is static, so every call to this function - overwrites the previous. -**************************************************************************/ -const char *unit_tired_attack_string(const struct unit *punit) -{ - static char buf[MAX_LEN_LINK]; - - if (is_tired_attack(punit->moves_left)) { - fc_snprintf(buf, sizeof(buf), - /* TRANS: tired; note trailing space */ - _("tired ")); - } else { - buf[0] = '\0'; - } - return buf; -} - -/**********************************************************************//** - Get string of unit's firepower text, i.e. "FP:2 " - If firepower is equal to one, then an empty string is returned - so as to shorten the text output. - N.B.: The returned string is static, so every call to this function - overwrites the previous. -**************************************************************************/ -const char *unit_firepower_if_not_one(int firepower) -{ - static char buf[MAX_LEN_LINK]; - - if (firepower == 1) { - buf[0] = '\0'; - } else { - fc_snprintf(buf, sizeof(buf), - /* TRANS: FP = Firepower of a unit; note trailing space */ - _("FP:%d "), - firepower); - } - return buf; -} - /**********************************************************************//** Get a text link to an unit. N.B.: The returned string is static, so every call to this function diff --git a/common/featured_text.h b/common/featured_text.h index 6c6404d6fe..43d4620957 100644 --- a/common/featured_text.h +++ b/common/featured_text.h @@ -242,10 +242,6 @@ const char *city_tile_link(const struct city *pcity); const char *tile_link(const struct tile *ptile); const char *unit_link(const struct unit *punit); const char *unit_tile_link(const struct unit *punit); -const char *unit_veteran_level_string(const struct unit *punit); -const char *unit_achieved_rank_string(const struct unit *punit); -const char *unit_tired_attack_string(const struct unit *punit); -const char *unit_firepower_if_not_one(int firepower); #ifdef __cplusplus } diff --git a/server/unithand.c b/server/unithand.c index 71488d8b26..a54ba67515 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -4643,6 +4643,87 @@ static bool unit_do_destroy_city(struct player *act_player, return TRUE; } +/**********************************************************************//** + Get a text of a unit's vet level. + N.B.: The returned string is static, so every call to this function + overwrites the previous. +**************************************************************************/ +static const char *unit_veteran_level_string(const struct unit *punit) +{ + static char buf[MAX_LEN_LINK]; + const struct veteran_level *vlevel; + + if (!punit) { + buf[0] = '\0'; /* If no unit, return empty string */ + return buf; + } + + vlevel = utype_veteran_level(unit_type_get(punit), punit->veteran); + fc_snprintf(buf, sizeof(buf), "%s", name_translation_get(&vlevel->name)); + + return buf; +} + +/**********************************************************************//** + Get string of when unit gets upgraded to new veteran level. + N.B.: The returned string is static, so every call to this function + overwrites the previous. +**************************************************************************/ +static const char *unit_achieved_rank_string(const struct unit *punit) +{ + static char buf[MAX_LEN_LINK]; + + fc_snprintf(buf, sizeof(buf), + /* TRANS: " and achieved the rank of "; + * preserve leading space */ + _(" and achieved the rank of %s"), + unit_veteran_level_string(punit)); + return buf; +} + +/**********************************************************************//** + Get string of unit's attack would be a tired attack or not. + N.B.: The returned string is static, so every call to this function + overwrites the previous. +**************************************************************************/ +static const char *unit_tired_attack_string(const struct unit *punit) +{ + static char buf[MAX_LEN_LINK]; + + if (is_tired_attack(punit->moves_left)) { + fc_snprintf(buf, sizeof(buf), + /* TRANS: tired; note trailing space */ + _("tired ")); + } else { + buf[0] = '\0'; + } + + return buf; +} + +/**********************************************************************//** + Get string of unit's firepower text, i.e. "FP:2 " + If firepower is equal to one, then an empty string is returned + so as to shorten the text output. + N.B.: The returned string is static, so every call to this function + overwrites the previous. +**************************************************************************/ +static const char *unit_firepower_if_not_one(int firepower) +{ + static char buf[MAX_LEN_LINK]; + + if (firepower == 1) { + buf[0] = '\0'; + } else { + fc_snprintf(buf, sizeof(buf), + /* TRANS: FP = Firepower of a unit; note trailing space */ + _("FP:%d "), + firepower); + } + + return buf; +} + /**********************************************************************//** Do a "regular" attack. -- 2.34.1