Skip to content

Commit 9788ca4

Browse files
committed
Fix Items::getDescription
* Display correct quality level for items with "non-displayed" improvements * Add ALL item designations here (and remove "XXwearXX" from other spot) * Obey SHOW_IMP_QUALITY setting
1 parent 2cd2a92 commit 9788ca4

File tree

2 files changed

+47
-12
lines changed

2 files changed

+47
-12
lines changed

docs/changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Template for new versions:
9595
- ``Buildings`` module: add ``getOwner`` (using the ``Units::get_cached_unit_by_global_id`` mechanic) to reflect changes in 51.11
9696
- ``Units::teleport``: projectile information is now cleared for teleported units
9797
- ``Buildings::setOwner``: updated for changes in 51.11
98+
- ``Items::getDescription``: fixed display of quality levels, now displays ALL item designations (in correct order) and obeys SHOW_IMP_QUALITY
9899

99100
## Lua
100101
- ``dfhack.military.addToSquad``: expose Military API function

library/modules/Items.cpp

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ distribution.
4949
#include "df/caravan_state.h"
5050
#include "df/creature_raw.h"
5151
#include "df/dfhack_material_category.h"
52+
#include "df/d_init.h"
5253
#include "df/entity_buy_prices.h"
5354
#include "df/entity_buy_requests.h"
5455
#include "df/entity_raw.h"
@@ -678,14 +679,54 @@ string Items::getDescription(df::item *item, int type, bool decorate) {
678679
item->getItemDescription(&tmp, type);
679680

680681
if (decorate) {
681-
addQuality(tmp, item->getQuality());
682+
// Special indicators get added in a specific order
683+
// Innermost is at the top, and outermost is at the bottom
682684

683-
if (item->isImproved()) {
685+
// First, figure out the quality levels we're going to display
686+
int craftquality = item->getQuality();
687+
int craftquality_only_imps = item->getImprovementQuality();
688+
bool has_displayed_item_improvements = item->isImproved();
689+
if (!has_displayed_item_improvements && (craftquality < craftquality_only_imps))
690+
craftquality = craftquality_only_imps;
691+
692+
// First, actual item quality
693+
addQuality(tmp, craftquality);
694+
695+
// Next, magic enchants
696+
if (item->getMagic() != NULL)
697+
tmp = '\x11' + tmp + '\x10'; // <| |>
698+
699+
// Next, improvements
700+
if (has_displayed_item_improvements) {
684701
tmp = '\xAE' + tmp + '\xAF'; // («) + tmp + (»)
685-
addQuality(tmp, item->getImprovementQuality());
702+
if (df::global::d_init->display.flags.is_set(d_init_flags1::SHOW_IMP_QUALITY))
703+
addQuality(tmp, craftquality_only_imps);
704+
}
705+
706+
// Dwarf mode only, forbid/foreign
707+
if (*df::global::gamemode == game_mode::DWARF) {
708+
if (item->flags.bits.forbid)
709+
tmp = '{' + tmp + '}';
710+
if (item->flags.bits.foreign)
711+
tmp = '(' + tmp + ')';
712+
}
713+
714+
// Wear
715+
switch (item->getWear())
716+
{
717+
case 1: tmp = 'x' + tmp + 'x'; break;
718+
case 2: tmp = 'X' + tmp + 'X'; break;
719+
case 3: tmp = "XX" + tmp + "XX"; break;
686720
}
687-
if (item->flags.bits.foreign)
688-
tmp = "(" + tmp + ")";
721+
722+
// Fire
723+
if (item->flags.bits.on_fire)
724+
tmp = '\x13' + tmp + '\x13'; // !! !!
725+
726+
// Finally, Adventure civzone
727+
if ((*df::global::gamemode == game_mode::ADVENTURE) &&
728+
Items::getGeneralRef(item, general_ref_type::BUILDING_CIVZONE_ASSIGNED) != NULL)
729+
tmp = '$' + tmp + '$';
689730
}
690731
return tmp;
691732
}
@@ -721,13 +762,6 @@ string Items::getReadableDescription(df::item *item) {
721762
CHECK_NULL_POINTER(item);
722763
auto desc = get_base_desc(item);
723764

724-
switch (item->getWear())
725-
{
726-
case 1: desc = "x" + desc + "x"; break; // Worn
727-
case 2: desc = "X" + desc + "X"; break; // Threadbare
728-
case 3: desc = "XX" + desc + "XX"; break; // Tattered
729-
}
730-
731765
if (auto gref = Items::getGeneralRef(item, general_ref_type::CONTAINS_UNIT)) {
732766
if (auto unit = gref->getUnit())
733767
{

0 commit comments

Comments
 (0)