Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display affix rolls/tier #7400

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
7 changes: 7 additions & 0 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1800,6 +1800,13 @@ void InitKeymapActions()
DoAutoMap,
nullptr,
IsGameRunning);
sgOptions.Keymapper.AddAction(
"Show Affix Data",
N_("Show affix data"),
N_("Shows detailed affix data while held."),
SDLK_LCTRL,
[] { showDetailedAffixData = true; },
[] { showDetailedAffixData = false; });
sgOptions.Keymapper.AddAction(
"CycleAutomapType",
N_("Cycle map type"),
Expand Down
51 changes: 51 additions & 0 deletions Source/itemdat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ std::vector<PLStruct> ItemPrefixes;
/** Contains the data related to each item suffix. */
std::vector<PLStruct> ItemSuffixes;

std::unordered_map<uint32_t, std::pair<const PLStruct *, const PLStruct *>> affixDataCache;
bool showDetailedAffixData = false;

namespace {

tl::expected<item_drop_rate, std::string> ParseItemDropRate(std::string_view value)
Expand Down Expand Up @@ -619,6 +622,52 @@ void LoadItemAffixesDat(std::string_view filename, std::vector<PLStruct> &out)
out.shrink_to_fit();
}



void generateAffixDataMap()
{
struct AffixMinMaxRolls {
std::string name;
int minRoll;
int maxRoll;
};

std::unordered_map<item_effect_type, std::vector<AffixMinMaxRolls>> m;
std::unordered_map<std::string, std::pair<uint8_t, uint8_t>> m2;
auto fillAffixDataMap = [&m](std::vector<PLStruct> &out) {
for (const auto &affix : out) {
m[affix.power.type].push_back({ affix.PLName, affix.power.param1, affix.power.param2 });
}
};

fillAffixDataMap(ItemPrefixes);
fillAffixDataMap(ItemSuffixes);

for (auto &[key, val] : m) {
std::sort(val.begin(), val.end(), [](const auto &lhs, const auto &rhs) {
return std::abs(lhs.minRoll) < std::abs(rhs.minRoll);
});

uint8_t num = 0;
for (const auto& affix : val) {
auto &affixData = m2[affix.name];
affixData = {
++num, static_cast<uint8_t>(val.size())
};
}
}

auto addAffixTierData = [&m, &m2](auto& affixVector) {
for (auto &affix : affixVector) {
auto &affixData = m[affix.power.type];
const auto &data = m2[affix.PLName];
affix.currentTier = data.first;
affix.maxTier = data.second;
}
};
addAffixTierData(ItemPrefixes);
addAffixTierData(ItemSuffixes);
}
} // namespace

void LoadItemData()
Expand All @@ -627,6 +676,8 @@ void LoadItemData()
LoadUniqueItemDat();
LoadItemAffixesDat("txtdata\\items\\item_prefixes.tsv", ItemPrefixes);
LoadItemAffixesDat("txtdata\\items\\item_suffixes.tsv", ItemSuffixes);

generateAffixDataMap();
}

std::string_view ItemTypeToString(ItemType itemType)
Expand Down
5 changes: 5 additions & 0 deletions Source/itemdat.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ struct PLStruct {
int minVal;
int maxVal;
int multVal;
uint8_t currentTier;
uint8_t maxTier;
};

struct UniqueItem {
Expand All @@ -650,6 +652,9 @@ extern std::vector<PLStruct> ItemPrefixes;
extern std::vector<PLStruct> ItemSuffixes;
extern std::vector<UniqueItem> UniqueItems;

extern std::unordered_map<uint32_t, std::pair<const PLStruct *, const PLStruct *>> affixDataCache;
extern bool showDetailedAffixData;

void LoadItemData();

} // namespace devilution
21 changes: 20 additions & 1 deletion Source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2428,6 +2428,7 @@ std::string GetTranslatedItemNameMagical(const Item &item, bool hellfireItem, bo
if (forceNameLengthCheck ? *forceNameLengthCheck : !StringInPanel(identifiedName.c_str())) {
identifiedName = GenerateMagicItemName(_(baseItemData.iSName), pPrefix, pSufix, translate);
}
affixDataCache[item._iSeed] = {pPrefix, pSufix};
}

SetRndSeed(currentSeed);
Expand Down Expand Up @@ -3819,7 +3820,7 @@ bool DoOil(Player &player, int cii)
return true;
}

[[nodiscard]] StringOrView PrintItemPower(char plidx, const Item &item)
[[nodiscard]] StringOrView PrintItemPowerRaw(char plidx, const Item &item)
{
switch (plidx) {
case IPL_TOHIT:
Expand Down Expand Up @@ -4026,6 +4027,24 @@ bool DoOil(Player &player, int cii)
}
}

[[nodiscard]] StringOrView PrintItemPower(char plidx, const Item &item)
{
if (showDetailedAffixData && item._iMagical == ITEM_QUALITY_MAGIC && item._iIdentified) {
if (auto cache = affixDataCache.find(item._iSeed); cache != affixDataCache.end()) {
const auto &[prefix, suffix] = cache->second;
const PLStruct *affix = prefix != nullptr && prefix->power.type == plidx ? prefix : suffix;
std::stringstream rolls;
if (affix->power.param1 != affix->power.param2 && affix->power.param2 != 0)
rolls << "stat range [" << affix->power.param1 << "/" << affix->power.param2 << "] ";

std::stringstream tier;
tier << "| tier [" << static_cast<unsigned>(affix->currentTier) << "/" << static_cast<unsigned>(affix->maxTier) << "]";
return rolls.str() + tier.str();
}
}
return PrintItemPowerRaw(plidx, item);
}

void DrawUniqueInfo(const Surface &out)
{
const Point position = DrawUniqueInfoWindow(out);
Expand Down
Loading