From 3a6893de53ee3994aa68641dd8b49a423ff617ab Mon Sep 17 00:00:00 2001 From: TaxiService Date: Sat, 1 Apr 2023 16:43:05 +0200 Subject: [PATCH] attempt to increase code readability following lethosor and myk's suggestions, each symbol now is its own constant with a descriptive name. ...will it work though? --- library/modules/Items.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp index 9c1217c93..75951aaa5 100644 --- a/library/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -720,13 +720,18 @@ df::coord Items::getPosition(df::item *item) return item->pos; } -static int quality_table[] = { 0, 45, 43, 42, 240, 15 }; +static const char MARKER_EXCEPTIONAL = static_cast(240); +static const char MARKER_MASTERWORK = static_cast(15); +static const char MARKER_IMPROVED_LEFT = static_cast(174); +static const char MARKER_IMPROVED_RIGHT = static_cast(175); + +static char quality_table[] = { 0, '-', '+', '*', MARKER_EXCEPTIONAL, MARKER_MASTERWORK }; static void addQuality(std::string &tmp, int quality) { if (quality > 0 && quality <= 5) { - int c = quality_table[quality]; - tmp = static_cast(c) + tmp + static_cast(c); + char c = quality_table[quality]; + tmp = c + tmp + c; } } @@ -825,7 +830,7 @@ std::string Items::getDescription(df::item *item, int type, bool decorate) addQuality(tmp, item->getQuality()); if (item->isImproved()) { - tmp = static_cast(174) + tmp + static_cast(175); + tmp = MARKER_IMPROVED_LEFT + tmp + MARKER_IMPROVED_RIGHT; addQuality(tmp, item->getImprovementQuality()); } }