Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Template for new versions:
- ``Buildings`` module: add ``getOwner`` (using the ``Units::get_cached_unit_by_global_id`` mechanic) to reflect changes in 51.11
- ``Units::teleport``: projectile information is now cleared for teleported units
- ``Buildings::setOwner``: updated for changes in 51.11
- ``Items::getDescription``: fixed display of quality levels, now displays ALL item designations (in correct order) and obeys SHOW_IMP_QUALITY

## Lua
- ``dfhack.military.addToSquad``: expose Military API function
Expand Down
58 changes: 46 additions & 12 deletions library/modules/Items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ distribution.
#include "df/caravan_state.h"
#include "df/creature_raw.h"
#include "df/dfhack_material_category.h"
#include "df/d_init.h"
#include "df/entity_buy_prices.h"
#include "df/entity_buy_requests.h"
#include "df/entity_raw.h"
Expand Down Expand Up @@ -678,14 +679,54 @@ string Items::getDescription(df::item *item, int type, bool decorate) {
item->getItemDescription(&tmp, type);

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

if (item->isImproved()) {
// First, figure out the quality levels we're going to display
int craftquality = item->getQuality();
int craftquality_only_imps = item->getImprovementQuality();
bool has_displayed_item_improvements = item->isImproved();
if (!has_displayed_item_improvements && (craftquality < craftquality_only_imps))
craftquality = craftquality_only_imps;

// First, actual item quality
addQuality(tmp, craftquality);

// Next, magic enchants
if (item->getMagic() != NULL)
tmp = '\x11' + tmp + '\x10'; // <| |>

// Next, improvements
if (has_displayed_item_improvements) {
tmp = '\xAE' + tmp + '\xAF'; // («) + tmp + (»)
addQuality(tmp, item->getImprovementQuality());
if (df::global::d_init->display.flags.is_set(d_init_flags1::SHOW_IMP_QUALITY))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

although we've traditionally tested globals before using them in the core library, I think this function is well out of the way of the code path that might be hit when globals aren't defined, so this is fine.

addQuality(tmp, craftquality_only_imps);
}

// Dwarf mode only, forbid/foreign
if (*df::global::gamemode == game_mode::DWARF) {
if (item->flags.bits.forbid)
tmp = '{' + tmp + '}';
if (item->flags.bits.foreign)
tmp = '(' + tmp + ')';
}

// Wear
switch (item->getWear())
{
case 1: tmp = 'x' + tmp + 'x'; break;
case 2: tmp = 'X' + tmp + 'X'; break;
case 3: tmp = "XX" + tmp + "XX"; break;
}
if (item->flags.bits.foreign)
tmp = "(" + tmp + ")";

// Fire
if (item->flags.bits.on_fire)
tmp = '\x13' + tmp + '\x13'; // !! !!

// Finally, Adventure civzone
if ((*df::global::gamemode == game_mode::ADVENTURE) &&
Items::getGeneralRef(item, general_ref_type::BUILDING_CIVZONE_ASSIGNED) != NULL)
tmp = '$' + tmp + '$';
}
return tmp;
}
Expand Down Expand Up @@ -721,13 +762,6 @@ string Items::getReadableDescription(df::item *item) {
CHECK_NULL_POINTER(item);
auto desc = get_base_desc(item);

switch (item->getWear())
{
case 1: desc = "x" + desc + "x"; break; // Worn
case 2: desc = "X" + desc + "X"; break; // Threadbare
case 3: desc = "XX" + desc + "XX"; break; // Tattered
}

if (auto gref = Items::getGeneralRef(item, general_ref_type::CONTAINS_UNIT)) {
if (auto unit = gref->getUnit())
{
Expand Down