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

Item TRNs #7081

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
2 changes: 2 additions & 0 deletions CMake/Assets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ set(devilutionx_assets
arena/church.dun
arena/circle_of_death.dun
arena/hell.dun
data/inv/trn/breast_plate.trn
data/inv/trn/unique/najs_light_plate.trn
data/boxleftend.clx
data/boxmiddle.clx
data/boxrightend.clx
Expand Down
6 changes: 5 additions & 1 deletion Source/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,11 @@ void DrawItem(const Item &item, const Surface &out, Point position, ClxSprite cl
{
const bool usable = !IsInspectingPlayer() ? item._iStatFlag : InspectPlayer->CanUseItem(item);
if (usable) {
ClxDraw(out, position, clx);
if (item.itemTRN) {
ClxDrawTRN(out, position, clx, item.itemTRN.get());
} else {
ClxDraw(out, position, clx);
}
} else {
ClxDrawTRN(out, position, clx, GetInfravisionTRN());
}
Expand Down
2 changes: 2 additions & 0 deletions Source/itemdat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ void LoadItemDat()
reader.read("class", item.iClass, ParseItemClass);
reader.read("equipType", item.iLoc, ParseItemEquipType);
reader.read("cursorGraphic", item.iCurs, ParseItemCursorGraphic);
reader.readString("trn", item.iTrnName);
reader.read("itemType", item.itype, ParseItemType);
reader.read("uniqueBaseItem", item.iItemId, ParseUniqueBaseItem);
reader.readString("name", item.iName);
Expand Down Expand Up @@ -579,6 +580,7 @@ void LoadUniqueItemDat()
UniqueItem &item = UniqueItems.emplace_back();
reader.readString("name", item.UIName);
reader.read("cursorGraphic", item.UICurs, ParseItemCursorGraphic);
reader.readString("trn", item.UITrnName);
reader.read("uniqueBaseItem", item.UIItemId, ParseUniqueBaseItem);
reader.readInt("minLevel", item.UIMinLvl);
reader.readInt("value", item.UIValue);
Expand Down
2 changes: 2 additions & 0 deletions Source/itemdat.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ struct ItemData {
enum item_class iClass;
enum item_equip_type iLoc;
enum item_cursor_graphic iCurs;
std::string iTrnName;
enum ItemType itype;
enum unique_base_item iItemId;
std::string iName;
Expand Down Expand Up @@ -636,6 +637,7 @@ struct PLStruct {
struct UniqueItem {
std::string UIName;
enum item_cursor_graphic UICurs;
std::string UITrnName;
enum unique_base_item UIItemId;
int8_t UIMinLvl;
uint8_t UINumPL;
Expand Down
31 changes: 31 additions & 0 deletions Source/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "engine/clx_sprite.hpp"
#include "engine/dx.h"
#include "engine/load_cel.hpp"
#include "engine/load_file.hpp"
#include "engine/random.hpp"
#include "engine/render/clx_render.hpp"
#include "engine/render/text_render.hpp"
Expand Down Expand Up @@ -1516,6 +1517,29 @@ int GetItemBLevel(int lvl, item_misc_id miscId, bool onlygood, bool uper15)
return iblvl;
}

void InitItemTRN(Item &item)
{
char filestr[64];
std::string trnName;
const char *path;

if ((item._iCreateInfo & CF_UNIQUE) != 0) {
trnName = UniqueItems[item._iUid].UITrnName;
path = R"(data\inv\trn\unique\)";
} else {
trnName = AllItemsList[item.IDidx].iTrnName;
path = R"(data\inv\trn\)";
}

if (!trnName.empty()) {
*BufCopy(filestr, path, trnName, ".trn") = '\0';
SDL_Log("%s", filestr);
item.itemTRN = LoadFileInMem<uint8_t>(filestr);
if (item.itemTRN)
SDL_Log("InitItemTRN: got trn for %s", item._iIName);
}
}

void SetupAllItems(const Player &player, Item &item, _item_indexes idx, uint32_t iseed, int lvl, int uper, bool onlygood, bool recreate, bool pregen)
{
item._iSeed = iseed;
Expand Down Expand Up @@ -1556,6 +1580,13 @@ void SetupAllItems(const Player &player, Item &item, _item_indexes idx, uint32_t
}
}
SetupItem(item);

const auto &itemTrn = AllItemsList[item.IDidx].iTrnName;

if (!itemTrn.empty()) {
SDL_Log("SetupAllItems(): %s is the itemTrn, so we call InitItemTRN", itemTrn.c_str());
InitItemTRN(item);
}
}

void SetupBaseItem(Point position, _item_indexes idx, bool onlygood, bool sendmsg, bool delta, bool spawn = false)
Expand Down
1 change: 1 addition & 0 deletions Source/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ constexpr int ItemAnimWidth = 96;
struct Player;

struct Item {
std::shared_ptr<uint8_t[]> itemTRN;
/** Randomly generated identifier */
uint32_t _iSeed = 0;
uint16_t _iCreateInfo = 0;
Expand Down
Binary file added assets/data/inv/trn/breast_plate.trn
Binary file not shown.
Binary file added assets/data/inv/trn/unique/najs_light_plate.trn
Binary file not shown.
338 changes: 169 additions & 169 deletions assets/txtdata/items/itemdat.tsv

Large diffs are not rendered by default.

222 changes: 111 additions & 111 deletions assets/txtdata/items/unique_itemdat.tsv

Large diffs are not rendered by default.