Browse Source

🚚 Rename 'ItemStruct' to 'Item'

pull/2758/head
Juliano Leal Goncalves 5 years ago committed by Anders Jenbo
parent
commit
bb2dfdfb73
  1. 2
      Source/control.cpp
  2. 4
      Source/controls/plrctrls.cpp
  3. 2
      Source/engine/render/cel_render.cpp
  4. 2
      Source/engine/render/cel_render.hpp
  5. 70
      Source/inv.cpp
  6. 16
      Source/inv.h
  7. 12
      Source/inv_iterators.hpp
  8. 120
      Source/items.cpp
  9. 36
      Source/items.h
  10. 14
      Source/loadsave.cpp
  11. 2
      Source/loadsave.h
  12. 2
      Source/msg.h
  13. 2
      Source/objects.cpp
  14. 8
      Source/pack.cpp
  15. 4
      Source/pack.h
  16. 12
      Source/player.cpp
  17. 14
      Source/player.h
  18. 4
      Source/qol/itemlabels.cpp
  19. 30
      Source/stores.cpp
  20. 16
      Source/stores.h
  21. 4
      test/inv_test.cpp
  22. 22
      test/pack_test.cpp
  23. 2
      test/player_test.h
  24. 4
      test/stores_test.cpp

2
Source/control.cpp

@ -444,7 +444,7 @@ int CapStatPointsToAdd(int remainingStatPoints, const Player &player, CharacterA
return std::min(remainingStatPoints, pointsToReachCap);
}
int DrawDurIcon4Item(const Surface &out, ItemStruct &pItem, int x, int c)
int DrawDurIcon4Item(const Surface &out, Item &pItem, int x, int c)
{
if (pItem.isEmpty())
return x;

4
Source/controls/plrctrls.cpp

@ -585,7 +585,7 @@ Size GetItemSizeOnSlot(int slot, char &itemInvId)
iv = -ii;
}
ItemStruct &item = myPlayer.InvList[iv - 1];
Item &item = myPlayer.InvList[iv - 1];
if (!item.isEmpty()) {
auto size = GetInvItemSize(item._iCurs + CURSOR_FIRSTITEM);
size.width /= InventorySlotSizeInPixels.width;
@ -1467,7 +1467,7 @@ void PerformSpellAction()
void CtrlUseInvItem()
{
ItemStruct *item;
Item *item;
if (pcursinvitem == -1)
return;

2
Source/engine/render/cel_render.cpp

@ -649,7 +649,7 @@ void CelDrawLightRedTo(const Surface &out, Point position, const CelSprite &cel,
RenderCelWithLightTable(out, position, pRLEBytes, nDataSize, cel.Width(frame), GetLightTable(1));
}
void CelDrawItem(const ItemStruct &item, const Surface &out, Point position, const CelSprite &cel, int frame)
void CelDrawItem(const Item &item, const Surface &out, Point position, const CelSprite &cel, int frame)
{
bool usable = item._iStatFlag;
if (!usable) {

2
Source/engine/render/cel_render.hpp

@ -91,7 +91,7 @@ void CelDrawLightRedTo(const Surface &out, Point position, const CelSprite &cel,
* @param cel CEL sprite
* @param frame CEL frame number
*/
void CelDrawItem(const ItemStruct &item, const Surface &out, Point position, const CelSprite &cel, int frame);
void CelDrawItem(const Item &item, const Surface &out, Point position, const CelSprite &cel, int frame);
/**
* @brief Blit a solid colder shape one pixel larger than the given sprite shape, to the target buffer at the given coordianates

70
Source/inv.cpp

@ -181,7 +181,7 @@ void AddItemToInvGrid(Player &player, int invGridIndex, int invListIndex, Size i
* @param item The item whose size is to be determined.
* @return The size, in inventory cells, of the item.
*/
Size GetInventorySize(const ItemStruct &item)
Size GetInventorySize(const Item &item)
{
int itemSizeIndex = item._iCurs + CURSOR_FIRSTITEM;
auto size = GetInvItemSize(itemSizeIndex);
@ -194,7 +194,7 @@ Size GetInventorySize(const ItemStruct &item)
* @param item The item to be checked.
* @return 'True' in case the item can fit a belt slot and 'False' otherwise.
*/
bool FitsInBeltSlot(const ItemStruct &item)
bool FitsInBeltSlot(const Item &item)
{
return GetInventorySize(item) == Size { 1, 1 };
}
@ -205,7 +205,7 @@ bool FitsInBeltSlot(const ItemStruct &item)
* @param item The item to be checked.
* @return 'True' in case the item can be placed on the belt and 'False' otherwise.
*/
bool CanBePlacedOnBelt(const ItemStruct &item)
bool CanBePlacedOnBelt(const Item &item)
{
return FitsInBeltSlot(item)
&& item._itype != ITYPE_GOLD
@ -219,27 +219,27 @@ bool CanBePlacedOnBelt(const ItemStruct &item)
* @param item The item to check.
* @return 'True' in case the item could be equipped in a player, and 'False' otherwise.
*/
bool CanEquip(const ItemStruct &item)
bool CanEquip(const Item &item)
{
return item.isEquipment()
&& item._iStatFlag;
}
/**
* @brief A specialized version of 'CanEquip(int, ItemStruct&, int)' that specifically checks whether the item can be equipped
* @brief A specialized version of 'CanEquip(int, Item&, int)' that specifically checks whether the item can be equipped
* in one/both of the player's hands.
* @param player The player whose inventory will be checked for compatibility with the item.
* @param item The item to check.
* @return 'True' if the player can currently equip the item in either one of his hands (i.e. the required hands are empty and
* allow the item), and 'False' otherwise.
*/
bool CanWield(Player &player, const ItemStruct &item)
bool CanWield(Player &player, const Item &item)
{
if (!CanEquip(item) || (item._iLoc != ILOC_ONEHAND && item._iLoc != ILOC_TWOHAND))
return false;
ItemStruct &leftHandItem = player.InvBody[INVLOC_HAND_LEFT];
ItemStruct &rightHandItem = player.InvBody[INVLOC_HAND_RIGHT];
Item &leftHandItem = player.InvBody[INVLOC_HAND_LEFT];
Item &rightHandItem = player.InvBody[INVLOC_HAND_RIGHT];
if (leftHandItem.isEmpty() && rightHandItem.isEmpty()) {
return true;
@ -249,7 +249,7 @@ bool CanWield(Player &player, const ItemStruct &item)
return false;
}
ItemStruct &occupiedHand = !leftHandItem.isEmpty() ? leftHandItem : rightHandItem;
Item &occupiedHand = !leftHandItem.isEmpty() ? leftHandItem : rightHandItem;
// Barbarian can wield two handed swords and maces in one hand, so we allow equiping any sword/mace as long as his occupied
// hand has a shield (i.e. no dual wielding allowed)
@ -285,7 +285,7 @@ bool CanWield(Player &player, const ItemStruct &item)
* @return 'True' if the player can currently equip the item in the specified body location (i.e. the body location is empty and
* allows the item), and 'False' otherwise.
*/
bool CanEquip(Player &player, const ItemStruct &item, inv_body_loc bodyLocation)
bool CanEquip(Player &player, const Item &item, inv_body_loc bodyLocation)
{
if (!CanEquip(item) || player._pmode > PM_WALK3 || !player.InvBody[bodyLocation].isEmpty()) {
return false;
@ -324,7 +324,7 @@ bool CanEquip(Player &player, const ItemStruct &item, inv_body_loc bodyLocation)
* whether the player can equip the item but you don't want the item to actually be equipped. 'True' by default.
* @return 'True' if the item was equipped and 'False' otherwise.
*/
bool AutoEquip(int playerId, const ItemStruct &item, inv_body_loc bodyLocation, bool persistItem)
bool AutoEquip(int playerId, const Item &item, inv_body_loc bodyLocation, bool persistItem)
{
auto &player = Players[playerId];
@ -346,7 +346,7 @@ bool AutoEquip(int playerId, const ItemStruct &item, inv_body_loc bodyLocation,
return true;
}
int SwapItem(ItemStruct *a, ItemStruct *b)
int SwapItem(Item *a, Item *b)
{
std::swap(*a, *b);
@ -564,7 +564,7 @@ void CheckInvPaste(int pnum, Point cursorPosition)
break;
case ILOC_TWOHAND:
if (!player.InvBody[INVLOC_HAND_LEFT].isEmpty() && !player.InvBody[INVLOC_HAND_RIGHT].isEmpty()) {
ItemStruct tempitem = player.HoldItem;
Item tempitem = player.HoldItem;
if (player.InvBody[INVLOC_HAND_RIGHT]._itype == ITYPE_SHIELD)
player.HoldItem = player.InvBody[INVLOC_HAND_RIGHT];
else
@ -719,14 +719,14 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove)
return;
}
ItemStruct &holdItem = player.HoldItem;
Item &holdItem = player.HoldItem;
holdItem._itype = ITYPE_NONE;
bool automaticallyMoved = false;
bool automaticallyEquipped = false;
bool automaticallyUnequip = false;
ItemStruct &headItem = player.InvBody[INVLOC_HEAD];
Item &headItem = player.InvBody[INVLOC_HEAD];
if (r >= SLOTXY_HEAD_FIRST && r <= SLOTXY_HEAD_LAST && !headItem.isEmpty()) {
holdItem = headItem;
if (automaticMove) {
@ -740,7 +740,7 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove)
}
}
ItemStruct &leftRingItem = player.InvBody[INVLOC_RING_LEFT];
Item &leftRingItem = player.InvBody[INVLOC_RING_LEFT];
if (r == SLOTXY_RING_LEFT && !leftRingItem.isEmpty()) {
holdItem = leftRingItem;
if (automaticMove) {
@ -754,7 +754,7 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove)
}
}
ItemStruct &rightRingItem = player.InvBody[INVLOC_RING_RIGHT];
Item &rightRingItem = player.InvBody[INVLOC_RING_RIGHT];
if (r == SLOTXY_RING_RIGHT && !rightRingItem.isEmpty()) {
holdItem = rightRingItem;
if (automaticMove) {
@ -768,7 +768,7 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove)
}
}
ItemStruct &amuletItem = player.InvBody[INVLOC_AMULET];
Item &amuletItem = player.InvBody[INVLOC_AMULET];
if (r == SLOTXY_AMULET && !amuletItem.isEmpty()) {
holdItem = amuletItem;
if (automaticMove) {
@ -782,7 +782,7 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove)
}
}
ItemStruct &leftHandItem = player.InvBody[INVLOC_HAND_LEFT];
Item &leftHandItem = player.InvBody[INVLOC_HAND_LEFT];
if (r >= SLOTXY_HAND_LEFT_FIRST && r <= SLOTXY_HAND_LEFT_LAST && !leftHandItem.isEmpty()) {
holdItem = leftHandItem;
if (automaticMove) {
@ -796,7 +796,7 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove)
}
}
ItemStruct &rightHandItem = player.InvBody[INVLOC_HAND_RIGHT];
Item &rightHandItem = player.InvBody[INVLOC_HAND_RIGHT];
if (r >= SLOTXY_HAND_RIGHT_FIRST && r <= SLOTXY_HAND_RIGHT_LAST && !rightHandItem.isEmpty()) {
holdItem = rightHandItem;
if (automaticMove) {
@ -810,7 +810,7 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove)
}
}
ItemStruct &chestItem = player.InvBody[INVLOC_CHEST];
Item &chestItem = player.InvBody[INVLOC_CHEST];
if (r >= SLOTXY_CHEST_FIRST && r <= SLOTXY_CHEST_LAST && !chestItem.isEmpty()) {
holdItem = chestItem;
if (automaticMove) {
@ -846,7 +846,7 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove)
}
if (r >= SLOTXY_BELT_FIRST) {
ItemStruct &beltItem = player.SpdList[r - SLOTXY_BELT_FIRST];
Item &beltItem = player.SpdList[r - SLOTXY_BELT_FIRST];
if (!beltItem.isEmpty()) {
holdItem = beltItem;
if (automaticMove) {
@ -937,7 +937,7 @@ void CheckNaKrulNotes(Player &player)
}
int itemNum = ActiveItems[0];
ItemStruct tmp = Items[itemNum];
Item tmp = Items[itemNum];
memset(&Items[itemNum], 0, sizeof(*Items));
GetItemAttrs(Items[itemNum], IDI_FULLNOTE, 16);
SetupItem(Items[itemNum]);
@ -996,7 +996,7 @@ void CheckQuestItem(Player &player)
CheckNaKrulNotes(player);
}
void CleanupItems(ItemStruct *item, int ii)
void CleanupItems(Item *item, int ii)
{
dItem[item->position.x][item->position.y] = 0;
@ -1059,7 +1059,7 @@ bool PutItem(Player &player, Point &position)
return false;
}
bool CanUseStaff(ItemStruct &staff, spell_id spell)
bool CanUseStaff(Item &staff, spell_id spell)
{
return !staff.isEmpty()
&& (staff._iMiscId == IMISC_STAFF || staff._iMiscId == IMISC_UNIQUE)
@ -1272,7 +1272,7 @@ void DrawInvBelt(const Surface &out)
* @param persistItem Pass 'True' to actually place the item in the belt. The default is 'False'.
* @return 'True' in case the item can be placed on the player's belt and 'False' otherwise.
*/
bool AutoPlaceItemInBelt(Player &player, const ItemStruct &item, bool persistItem)
bool AutoPlaceItemInBelt(Player &player, const Item &item, bool persistItem)
{
if (!CanBePlacedOnBelt(item)) {
return false;
@ -1302,7 +1302,7 @@ bool AutoPlaceItemInBelt(Player &player, const ItemStruct &item, bool persistIte
* whether the player can equip the item but you don't want the item to actually be equipped. 'True' by default.
* @return 'True' if the item was equipped and 'False' otherwise.
*/
bool AutoEquip(int playerId, const ItemStruct &item, bool persistItem)
bool AutoEquip(int playerId, const Item &item, bool persistItem)
{
if (!CanEquip(item)) {
return false;
@ -1323,7 +1323,7 @@ bool AutoEquip(int playerId, const ItemStruct &item, bool persistItem)
* @param item The item to check.
* @return 'True' if auto-equipping behavior is enabled for the player and item and 'False' otherwise.
*/
bool AutoEquipEnabled(const Player &player, const ItemStruct &item)
bool AutoEquipEnabled(const Player &player, const Item &item)
{
if (item.isWeapon()) {
// Monk can use unarmed attack as an encouraged option, thus we do not automatically equip weapons on him so as to not
@ -1357,7 +1357,7 @@ bool AutoEquipEnabled(const Player &player, const ItemStruct &item)
* @param persistItem Pass 'True' to actually place the item in the inventory. The default is 'False'.
* @return 'True' in case the item can be placed on the player's inventory and 'False' otherwise.
*/
bool AutoPlaceItemInInventory(Player &player, const ItemStruct &item, bool persistItem)
bool AutoPlaceItemInInventory(Player &player, const Item &item, bool persistItem)
{
Size itemSize = GetInventorySize(item);
@ -1425,7 +1425,7 @@ bool AutoPlaceItemInInventory(Player &player, const ItemStruct &item, bool persi
* @param persistItem Pass 'True' to actually place the item in the inventory slot. The default is 'False'.
* @return 'True' in case the item can be placed on the specified player's inventory slot and 'False' otherwise.
*/
bool AutoPlaceItemInInventorySlot(Player &player, int slotIndex, const ItemStruct &item, bool persistItem)
bool AutoPlaceItemInInventorySlot(Player &player, int slotIndex, const Item &item, bool persistItem)
{
int yy = (slotIndex > 0) ? (10 * (slotIndex / 10)) : 0;
@ -1577,7 +1577,7 @@ void CheckInvScrn(bool isShiftHeld)
void CheckItemStats(Player &player)
{
ItemStruct &item = player.HoldItem;
Item &item = player.HoldItem;
item._iStatFlag = false;
@ -1588,7 +1588,7 @@ void CheckItemStats(Player &player)
}
}
void InvGetItem(int pnum, ItemStruct *item, int ii)
void InvGetItem(int pnum, Item *item, int ii)
{
if (dropGoldFlag) {
dropGoldFlag = false;
@ -1617,7 +1617,7 @@ void InvGetItem(int pnum, ItemStruct *item, int ii)
NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM);
}
void AutoGetItem(int pnum, ItemStruct *item, int ii)
void AutoGetItem(int pnum, Item *item, int ii)
{
bool done;
@ -1891,7 +1891,7 @@ int8_t CheckInvHLight()
int8_t rv = -1;
InfoColor = UiFlags::ColorSilver;
ItemStruct *pi = nullptr;
Item *pi = nullptr;
auto &myPlayer = Players[MyPlayerId];
ClearPanel();
@ -2033,7 +2033,7 @@ bool UseStaff()
bool UseInvItem(int pnum, int cii)
{
int c;
ItemStruct *item;
Item *item;
auto &player = Players[pnum];

16
Source/inv.h

@ -86,7 +86,7 @@ extern const Point InvRect[73];
/**
* @brief Function type which performs an operation on the given item.
*/
using ItemFunc = void (*)(ItemStruct &);
using ItemFunc = void (*)(Item &);
void FreeInvGFX();
void InitInv();
@ -97,11 +97,11 @@ void InitInv();
void DrawInv(const Surface &out);
void DrawInvBelt(const Surface &out);
bool AutoEquipEnabled(const Player &player, const ItemStruct &item);
bool AutoEquip(int playerId, const ItemStruct &item, bool persistItem = true);
bool AutoPlaceItemInInventory(Player &player, const ItemStruct &item, bool persistItem = false);
bool AutoPlaceItemInInventorySlot(Player &player, int slotIndex, const ItemStruct &item, bool persistItem);
bool AutoPlaceItemInBelt(Player &player, const ItemStruct &item, bool persistItem = false);
bool AutoEquipEnabled(const Player &player, const Item &item);
bool AutoEquip(int playerId, const Item &item, bool persistItem = true);
bool AutoPlaceItemInInventory(Player &player, const Item &item, bool persistItem = false);
bool AutoPlaceItemInInventorySlot(Player &player, int slotIndex, const Item &item, bool persistItem);
bool AutoPlaceItemInBelt(Player &player, const Item &item, bool persistItem = false);
bool GoldAutoPlace(Player &player);
bool GoldAutoPlaceInInventorySlot(Player &player, int slotIndex);
void CheckInvSwap(Player &player, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff);
@ -109,8 +109,8 @@ void inv_update_rem_item(Player &player, BYTE iv);
void CheckInvItem(bool isShiftHeld = false);
void CheckInvScrn(bool isShiftHeld);
void CheckItemStats(Player &player);
void InvGetItem(int pnum, ItemStruct *item, int ii);
void AutoGetItem(int pnum, ItemStruct *item, int ii);
void InvGetItem(int pnum, Item *item, int ii);
void AutoGetItem(int pnum, Item *item, int ii);
int FindGetItem(int idx, uint16_t ci, int iseed);
void SyncGetItem(Point position, int idx, uint16_t ci, int iseed);
bool CanPut(Point position);

12
Source/inv_iterators.hpp

@ -20,13 +20,13 @@ public:
public:
using iterator_category = std::forward_iterator_tag;
using difference_type = void;
using value_type = ItemStruct;
using value_type = Item;
using pointer = value_type *;
using reference = value_type &;
Iterator() = default;
Iterator(ItemStruct *items, std::size_t count, std::size_t index)
Iterator(Item *items, std::size_t count, std::size_t index)
: items_(items)
, count_(count)
, index_(index)
@ -81,12 +81,12 @@ public:
}
}
ItemStruct *items_ = nullptr;
Item *items_ = nullptr;
std::size_t count_ = 0;
std::size_t index_ = 0;
};
ItemsContainerRange(ItemStruct *items, std::size_t count)
ItemsContainerRange(Item *items, std::size_t count)
: items_(items)
, count_(count)
{
@ -103,7 +103,7 @@ public:
}
private:
ItemStruct *items_;
Item *items_;
std::size_t count_;
};
@ -116,7 +116,7 @@ public:
public:
using iterator_category = std::forward_iterator_tag;
using difference_type = void;
using value_type = ItemStruct;
using value_type = Item;
using pointer = value_type *;
using reference = value_type &;

120
Source/items.cpp

@ -36,7 +36,7 @@
namespace devilution {
/** Contains the items on ground in the current game. */
ItemStruct Items[MAXITEMS + 1];
Item Items[MAXITEMS + 1];
int ActiveItems[MAXITEMS];
int ActiveItemCount;
int AvailableItems[MAXITEMS];
@ -131,7 +131,7 @@ enum class PlayerArmorGraphic : uint8_t {
// clang-format on
};
ItemStruct curruitem;
Item curruitem;
/** Holds item get records, tracking items being recently looted. This is in an effort to prevent items being picked up more than once. */
ItemGetRecordStruct itemrecord[MAXITEMS];
@ -506,7 +506,7 @@ void CalcSelfItems(Player &player)
} while (changeflag);
}
bool ItemMinStats(const Player &player, ItemStruct &x)
bool ItemMinStats(const Player &player, Item &x)
{
if (player._pMagic < x._iMinMag)
return false;
@ -550,7 +550,7 @@ void WitchBookLevel(int ii)
}
}
bool StoreStatOk(ItemStruct &item)
bool StoreStatOk(Item &item)
{
const auto &myPlayer = Players[MyPlayerId];
@ -591,7 +591,7 @@ void CalcPlrBookVals(Player &player)
}
}
void SetPlrHandSeed(ItemStruct &item, int iseed)
void SetPlrHandSeed(Item &item, int iseed)
{
item._iSeed = iseed;
}
@ -666,7 +666,7 @@ void GetSuperItemSpace(Point position, int8_t inum)
}
}
void CalcItemValue(ItemStruct &item)
void CalcItemValue(Item &item)
{
int v = item._iVMult1 + item._iVMult2;
if (v > 0) {
@ -679,7 +679,7 @@ void CalcItemValue(ItemStruct &item)
item._iIvalue = std::max(v, 1);
}
void GetBookSpell(ItemStruct &item, int lvl)
void GetBookSpell(Item &item, int lvl)
{
int rv;
@ -762,7 +762,7 @@ int CalculateToHitBonus(int level)
}
}
int SaveItemPower(ItemStruct &item, const ItemPower &power)
int SaveItemPower(Item &item, const ItemPower &power)
{
int r = RndPL(power.param1, power.param2);
@ -1133,7 +1133,7 @@ int PLVal(int pv, int p1, int p2, int minv, int maxv)
return minv + (maxv - minv) * (100 * (pv - p1) / (p2 - p1)) / 100;
}
void SaveItemAffix(ItemStruct &item, const PLStruct &affix)
void SaveItemAffix(Item &item, const PLStruct &affix)
{
auto power = affix.power;
@ -1156,7 +1156,7 @@ void SaveItemAffix(ItemStruct &item, const PLStruct &affix)
}
}
void GetStaffPower(ItemStruct &item, int lvl, int bs, bool onlygood)
void GetStaffPower(Item &item, int lvl, int bs, bool onlygood)
{
int preidx = -1;
if (GenerateRnd(10) == 0 || onlygood) {
@ -1199,7 +1199,7 @@ void GetStaffPower(ItemStruct &item, int lvl, int bs, bool onlygood)
CalcItemValue(item);
}
void GetItemPower(ItemStruct &item, int minlvl, int maxlvl, affix_item_type flgs, bool onlygood)
void GetItemPower(Item &item, int minlvl, int maxlvl, affix_item_type flgs, bool onlygood)
{
int l[256];
char istr[128];
@ -1286,7 +1286,7 @@ void GetItemPower(ItemStruct &item, int minlvl, int maxlvl, affix_item_type flgs
CalcItemValue(item);
}
void GetStaffSpell(ItemStruct &item, int lvl, bool onlygood)
void GetStaffSpell(Item &item, int lvl, bool onlygood)
{
if (!gbIsHellfire && GenerateRnd(4) == 0) {
GetItemPower(item, lvl / 2, lvl, PLT_STAFF, onlygood);
@ -1339,7 +1339,7 @@ void GetStaffSpell(ItemStruct &item, int lvl, bool onlygood)
GetStaffPower(item, lvl, bs, onlygood);
}
void GetOilType(ItemStruct &item, int maxLvl)
void GetOilType(Item &item, int maxLvl)
{
int cnt = 2;
int8_t rnd[32] = { 5, 6 };
@ -1366,7 +1366,7 @@ void GetOilType(ItemStruct &item, int maxLvl)
item._iIvalue = OilValues[t];
}
void GetItemBonus(ItemStruct &item, int minlvl, int maxlvl, bool onlygood, bool allowspells)
void GetItemBonus(Item &item, int minlvl, int maxlvl, bool onlygood, bool allowspells)
{
if (minlvl > 25)
minlvl = 25;
@ -1501,7 +1501,7 @@ int RndTypeItems(int itype, int imid, int lvl)
return ril[GenerateRnd(ri)];
}
_unique_items CheckUnique(ItemStruct &item, int lvl, int uper, bool recreate)
_unique_items CheckUnique(Item &item, int lvl, int uper, bool recreate)
{
std::bitset<128> uok = {};
@ -1535,7 +1535,7 @@ _unique_items CheckUnique(ItemStruct &item, int lvl, int uper, bool recreate)
return (_unique_items)itemData;
}
void GetUniqueItem(ItemStruct &item, _unique_items uid)
void GetUniqueItem(Item &item, _unique_items uid)
{
UniqueItemFlags[uid] = true;
@ -1556,13 +1556,13 @@ void GetUniqueItem(ItemStruct &item, _unique_items uid)
item._iCreateInfo |= CF_UNIQUE;
}
void ItemRndDur(ItemStruct &item)
void ItemRndDur(Item &item)
{
if (item._iDurability > 0 && item._iDurability != DUR_INDESTRUCTIBLE)
item._iDurability = GenerateRnd(item._iMaxDur / 2) + (item._iMaxDur / 4) + 1;
}
void SetupAllItems(ItemStruct &item, int idx, int iseed, int lvl, int uper, bool onlygood, bool recreate, bool pregen)
void SetupAllItems(Item &item, int idx, int iseed, int lvl, int uper, bool onlygood, bool recreate, bool pregen)
{
int iblvl;
@ -1635,7 +1635,7 @@ void SetupBaseItem(Point position, int idx, bool onlygood, bool sendmsg, bool de
DeltaAddItem(ii);
}
void SetupAllUseful(ItemStruct &item, int iseed, int lvl)
void SetupAllUseful(Item &item, int iseed, int lvl)
{
int idx;
@ -1735,7 +1735,7 @@ void ItemDoppel()
for (int idoppelx = 16; idoppelx < 96; idoppelx++) {
if (dItem[idoppelx][idoppely] != 0) {
ItemStruct *i = &Items[dItem[idoppelx][idoppely] - 1];
Item *i = &Items[dItem[idoppelx][idoppely] - 1];
if (i->position.x != idoppelx || i->position.y != idoppely)
dItem[idoppelx][idoppely] = 0;
}
@ -1746,7 +1746,7 @@ void ItemDoppel()
idoppely = 16;
}
void RepairItem(ItemStruct &item, int lvl)
void RepairItem(Item &item, int lvl)
{
if (item._iDurability == item._iMaxDur) {
return;
@ -1770,7 +1770,7 @@ void RepairItem(ItemStruct &item, int lvl)
item._iDurability = std::min<int>(item._iDurability + rep, item._iMaxDur);
}
void RechargeItem(ItemStruct &item, int r)
void RechargeItem(Item &item, int r)
{
if (item._iCharges == item._iMaxCharges)
return;
@ -1786,7 +1786,7 @@ void RechargeItem(ItemStruct &item, int r)
item._iCharges = std::min(item._iCharges, item._iMaxCharges);
}
bool ApplyOilToItem(ItemStruct &item, Player &player)
bool ApplyOilToItem(Item &item, Player &player)
{
int r;
@ -2052,7 +2052,7 @@ void DrawUniqueInfoDevider(const Surface &out, int y)
memcpy(dst, src, 267); // BUGFIX: should be 267 (fixed)
}
void PrintItemMisc(ItemStruct &item)
void PrintItemMisc(Item &item)
{
if (item._iMiscId == IMISC_SCROLL) {
strcpy(tempstr, _("Right-click to read"));
@ -2101,7 +2101,7 @@ void PrintItemMisc(ItemStruct &item)
}
}
void PrintItemInfo(ItemStruct &item)
void PrintItemInfo(Item &item)
{
PrintItemMisc(item);
uint8_t str = item._iMinStr;
@ -2173,13 +2173,13 @@ int RndSmithItem(int lvl)
return RndVendorItem<SmithItemOk, true>(0, lvl);
}
void SortVendor(ItemStruct *itemList)
void SortVendor(Item *itemList)
{
int count = 1;
while (!itemList[count].isEmpty())
count++;
auto cmp = [](const ItemStruct &a, const ItemStruct &b) {
auto cmp = [](const Item &a, const Item &b) {
return a.IDidx < b.IDidx;
};
@ -2216,7 +2216,7 @@ void SpawnOnePremium(int i, int plvl, int playerId)
{
int itemValue = 0;
bool keepGoing = false;
ItemStruct tempItem = Items[0];
Item tempItem = Items[0];
auto &player = Players[playerId];
@ -2253,7 +2253,7 @@ void SpawnOnePremium(int i, int plvl, int playerId)
case ITYPE_MARMOR:
case ITYPE_HARMOR: {
const auto *const mostValuablePlayerArmor = player.GetMostValuableItem(
[](const ItemStruct &item) {
[](const Item &item) {
return item._itype == ITYPE_LARMOR
|| item._itype == ITYPE_MARMOR
|| item._itype == ITYPE_HARMOR;
@ -2272,7 +2272,7 @@ void SpawnOnePremium(int i, int plvl, int playerId)
case ITYPE_RING:
case ITYPE_AMULET: {
const auto *const mostValuablePlayerItem = player.GetMostValuableItem(
[](const ItemStruct &item) { return item._itype == Items[0]._itype; });
[](const Item &item) { return item._itype == Items[0]._itype; });
itemValue = mostValuablePlayerItem == nullptr ? 0 : mostValuablePlayerItem->_iIvalue;
break;
@ -2369,7 +2369,7 @@ int RndHealerItem(int lvl)
return RndVendorItem<HealerItemOk>(0, lvl);
}
void RecreateSmithItem(ItemStruct &item, int lvl, int iseed)
void RecreateSmithItem(Item &item, int lvl, int iseed)
{
SetRndSeed(iseed);
int itype = RndSmithItem(lvl) - 1;
@ -2380,7 +2380,7 @@ void RecreateSmithItem(ItemStruct &item, int lvl, int iseed)
item._iIdentified = true;
}
void RecreatePremiumItem(ItemStruct &item, int plvl, int iseed)
void RecreatePremiumItem(Item &item, int plvl, int iseed)
{
SetRndSeed(iseed);
int itype = RndPremiumItem(plvl / 4, plvl) - 1;
@ -2392,7 +2392,7 @@ void RecreatePremiumItem(ItemStruct &item, int plvl, int iseed)
item._iIdentified = true;
}
void RecreateBoyItem(ItemStruct &item, int lvl, int iseed)
void RecreateBoyItem(Item &item, int lvl, int iseed)
{
SetRndSeed(iseed);
int itype = RndBoyItem(lvl) - 1;
@ -2404,7 +2404,7 @@ void RecreateBoyItem(ItemStruct &item, int lvl, int iseed)
item._iIdentified = true;
}
void RecreateWitchItem(ItemStruct &item, int idx, int lvl, int iseed)
void RecreateWitchItem(Item &item, int idx, int lvl, int iseed)
{
if (idx == IDI_MANA || idx == IDI_FULLMANA || idx == IDI_PORTAL) {
GetItemAttrs(item, idx, lvl);
@ -2430,7 +2430,7 @@ void RecreateWitchItem(ItemStruct &item, int idx, int lvl, int iseed)
item._iIdentified = true;
}
void RecreateHealerItem(ItemStruct &item, int idx, int lvl, int iseed)
void RecreateHealerItem(Item &item, int idx, int lvl, int iseed)
{
if (idx == IDI_HEAL || idx == IDI_FULLHEAL || idx == IDI_RESURRECT) {
GetItemAttrs(item, idx, lvl);
@ -2445,7 +2445,7 @@ void RecreateHealerItem(ItemStruct &item, int idx, int lvl, int iseed)
item._iIdentified = true;
}
void RecreateTownItem(ItemStruct &item, int idx, uint16_t icreateinfo, int iseed)
void RecreateTownItem(Item &item, int idx, uint16_t icreateinfo, int iseed)
{
if ((icreateinfo & CF_SMITH) != 0)
RecreateSmithItem(item, icreateinfo & CF_LEVEL, iseed);
@ -2552,7 +2552,7 @@ bool IsItemAvailable(int i)
sgOptions.Gameplay.bTestBard && (i == IDI_BARDSWORD || i == IDI_BARDDAGGER));
}
BYTE GetOutlineColor(const ItemStruct &item, bool checkReq)
BYTE GetOutlineColor(const Item &item, bool checkReq)
{
if (checkReq && !item._iStatFlag)
return ICOL_RED;
@ -3004,7 +3004,7 @@ void CalcPlrInv(Player &player, bool loadgfx)
}
}
void SetPlrHandItem(ItemStruct &item, int itemData)
void SetPlrHandItem(Item &item, int itemData)
{
auto &pAllItem = AllItemsList[itemData];
@ -3043,12 +3043,12 @@ void SetPlrHandItem(ItemStruct &item, int itemData)
item.dwBuff |= CF_HELLFIRE;
}
void GetPlrHandSeed(ItemStruct *h)
void GetPlrHandSeed(Item *h)
{
h->_iSeed = AdvanceRndSeed();
}
void SetGoldSeed(Player &player, ItemStruct &gold)
void SetGoldSeed(Player &player, Item &gold)
{
int s = 0;
@ -3088,7 +3088,7 @@ int GetGoldCursor(int value)
* @brief Update the gold cursor on the given gold item
* @param h The item to update
*/
void SetPlrHandGoldCurs(ItemStruct &gold)
void SetPlrHandGoldCurs(Item &gold)
{
gold._iCurs = GetGoldCursor(gold._ivalue);
}
@ -3269,7 +3269,7 @@ Point GetSuperItemLoc(Point position)
return { 0, 0 }; // TODO handle no space for dropping items
}
void GetItemAttrs(ItemStruct &item, int itemData, int lvl)
void GetItemAttrs(Item &item, int itemData, int lvl)
{
item._itype = AllItemsList[itemData].itype;
item._iCurs = AllItemsList[itemData].iCurs;
@ -3326,7 +3326,7 @@ void GetItemAttrs(ItemStruct &item, int itemData, int lvl)
SetPlrHandGoldCurs(item);
}
void SetupItem(ItemStruct &item)
void SetupItem(Item &item)
{
item.SetNewAnimation(Players[MyPlayerId].pLvlLoad == 0);
item._iIdentified = false;
@ -3473,7 +3473,7 @@ void CreateTypeItem(Point position, bool onlygood, int itype, int imisc, bool se
SetupBaseItem(position, idx, onlygood, sendmsg, delta);
}
void RecreateItem(ItemStruct &item, int idx, uint16_t icreateinfo, int iseed, int ivalue, bool isHellfire)
void RecreateItem(Item &item, int idx, uint16_t icreateinfo, int iseed, int ivalue, bool isHellfire)
{
bool tmpIsHellfire = gbIsHellfire;
gbIsHellfire = isHellfire;
@ -3525,7 +3525,7 @@ void RecreateItem(ItemStruct &item, int idx, uint16_t icreateinfo, int iseed, in
gbIsHellfire = tmpIsHellfire;
}
void RecreateEar(ItemStruct &item, uint16_t ic, int iseed, int id, int dur, int mdur, int ch, int mch, int ivalue, int ibuff)
void RecreateEar(Item &item, uint16_t ic, int iseed, int id, int dur, int mdur, int ch, int mch, int ivalue, int ibuff)
{
SetPlrHandItem(item, IDI_EAR);
tempstr[0] = static_cast<char>((ic >> 8) & 0x7F);
@ -3685,7 +3685,7 @@ void SpawnTheodore(Point position)
SpawnRewardItem(IDI_THEODORE, position);
}
void RespawnItem(ItemStruct *item, bool flipFlag)
void RespawnItem(Item *item, bool flipFlag)
{
int it = ItemCAnimTbl[item->_iCurs];
item->SetNewAnimation(flipFlag);
@ -3745,12 +3745,12 @@ void FreeItemGFX()
}
}
void GetItemFrm(ItemStruct &item)
void GetItemFrm(Item &item)
{
item.AnimInfo.pCelSprite = &*itemanims[ItemCAnimTbl[item._iCurs]];
}
void GetItemStr(ItemStruct &item)
void GetItemStr(Item &item)
{
if (item._itype != ITYPE_GOLD) {
if (item._iIdentified)
@ -3767,7 +3767,7 @@ void GetItemStr(ItemStruct &item)
void CheckIdentify(Player &player, int cii)
{
ItemStruct *pi;
Item *pi;
if (cii >= NUM_INVLOC)
pi = &player.InvList[cii - NUM_INVLOC];
@ -3783,7 +3783,7 @@ void CheckIdentify(Player &player, int cii)
void DoRepair(Player &player, int cii)
{
ItemStruct *pi;
Item *pi;
PlaySfxLoc(IS_REPAIR, player.position.tile);
@ -3802,7 +3802,7 @@ void DoRepair(Player &player, int cii)
void DoRecharge(Player &player, int cii)
{
ItemStruct *pi;
Item *pi;
if (cii >= NUM_INVLOC) {
pi = &player.InvList[cii - NUM_INVLOC];
@ -3822,7 +3822,7 @@ void DoRecharge(Player &player, int cii)
void DoOil(Player &player, int cii)
{
ItemStruct *pi;
Item *pi;
if (cii >= NUM_INVLOC) {
pi = &player.InvList[cii - NUM_INVLOC];
} else {
@ -3835,7 +3835,7 @@ void DoOil(Player &player, int cii)
NewCursor(CURSOR_HAND);
}
void PrintItemPower(char plidx, ItemStruct *x)
void PrintItemPower(char plidx, Item *x)
{
switch (plidx) {
case IPL_TOHIT:
@ -4149,7 +4149,7 @@ void DrawUniqueInfo(const Surface &out)
}
}
void PrintItemDetails(ItemStruct *x)
void PrintItemDetails(Item *x)
{
if (x->_iClass == ICLASS_WEAPON) {
if (x->_iMinDam == x->_iMaxDam) {
@ -4196,7 +4196,7 @@ void PrintItemDetails(ItemStruct *x)
PrintItemInfo(*x);
}
void PrintItemDur(ItemStruct *x)
void PrintItemDur(Item *x)
{
if (x->_iClass == ICLASS_WEAPON) {
if (x->_iMinDam == x->_iMaxDam) {
@ -4443,7 +4443,7 @@ void SpawnSmith(int lvl)
{
constexpr int PinnedItemCount = 0;
ItemStruct holditem;
Item holditem;
holditem = Items[0];
int maxValue = 140000;
@ -4631,7 +4631,7 @@ void SpawnBoy(int lvl)
case ITYPE_MARMOR:
case ITYPE_HARMOR: {
const auto *const mostValuablePlayerArmor = myPlayer.GetMostValuableItem(
[](const ItemStruct &item) {
[](const Item &item) {
return item._itype == ITYPE_LARMOR
|| item._itype == ITYPE_MARMOR
|| item._itype == ITYPE_HARMOR;
@ -4650,7 +4650,7 @@ void SpawnBoy(int lvl)
case ITYPE_RING:
case ITYPE_AMULET: {
const auto *const mostValuablePlayerItem = myPlayer.GetMostValuableItem(
[itemType](const ItemStruct &item) { return item._itype == itemType; });
[itemType](const Item &item) { return item._itype == itemType; });
ivalue = mostValuablePlayerItem == nullptr ? 0 : mostValuablePlayerItem->_iIvalue;
break;
@ -4905,7 +4905,7 @@ std::string DebugSpawnItem(std::string itemName, bool unique)
int uper = (unique ? 15 : 1);
Point bkp = item.position;
memset(&item, 0, sizeof(ItemStruct));
memset(&item, 0, sizeof(Item));
item.position = bkp;
memset(UniqueItemFlags, 0, sizeof(UniqueItemFlags));
SetupAllItems(item, idx, AdvanceRndSeed(), fake_m.mLevel, uper, onlygood, false, false);
@ -4926,7 +4926,7 @@ std::string DebugSpawnItem(std::string itemName, bool unique)
}
#endif
void ItemStruct::SetNewAnimation(bool showAnimation)
void Item::SetNewAnimation(bool showAnimation)
{
int it = ItemCAnimTbl[_iCurs];
int numberOfFrames = ItemAnimLs[it];

36
Source/items.h

@ -171,7 +171,7 @@ enum icreateinfo_flag2 {
// All item animation frames have this width.
constexpr int ItemAnimWidth = 96;
struct ItemStruct {
struct Item {
/** Randomly generated identifier */
int32_t _iSeed;
uint16_t _iCreateInfo;
@ -393,12 +393,12 @@ struct ItemGetRecordStruct {
struct CornerStoneStruct {
Point position;
bool activated;
ItemStruct item;
Item item;
};
struct Player;
extern ItemStruct Items[MAXITEMS + 1];
extern Item Items[MAXITEMS + 1];
extern int ActiveItems[MAXITEMS];
extern int ActiveItemCount;
extern int AvailableItems[MAXITEMS];
@ -406,35 +406,35 @@ extern bool ShowUniqueItemInfoBox;
extern CornerStoneStruct CornerStone;
extern bool UniqueItemFlags[128];
BYTE GetOutlineColor(const ItemStruct &item, bool checkReq);
BYTE GetOutlineColor(const Item &item, bool checkReq);
bool IsItemAvailable(int i);
bool IsUniqueAvailable(int i);
void InitItemGFX();
void InitItems();
void CalcPlrItemVals(Player &player, bool Loadgfx);
void CalcPlrInv(Player &player, bool Loadgfx);
void SetPlrHandItem(ItemStruct &item, int itemData);
void GetPlrHandSeed(ItemStruct *h);
void SetPlrHandItem(Item &item, int itemData);
void GetPlrHandSeed(Item *h);
/**
* @brief Set a new unique seed value on the given item
*/
void SetGoldSeed(Player &player, ItemStruct &gold);
void SetGoldSeed(Player &player, Item &gold);
int GetGoldCursor(int value);
void SetPlrHandGoldCurs(ItemStruct &gold);
void SetPlrHandGoldCurs(Item &gold);
void CreatePlrItems(int playerId);
bool ItemSpaceOk(Point position);
int AllocateItem();
Point GetSuperItemLoc(Point position);
void GetItemAttrs(ItemStruct &item, int itemData, int lvl);
void SetupItem(ItemStruct &item);
void GetItemAttrs(Item &item, int itemData, int lvl);
void SetupItem(Item &item);
int RndItem(const MonsterStruct &monster);
void SpawnUnique(_unique_items uid, Point position);
void SpawnItem(MonsterStruct &monster, Point position, bool sendmsg);
void CreateRndItem(Point position, bool onlygood, bool sendmsg, bool delta);
void CreateRndUseful(Point position, bool sendmsg);
void CreateTypeItem(Point position, bool onlygood, int itype, int imisc, bool sendmsg, bool delta);
void RecreateItem(ItemStruct &item, int idx, uint16_t icreateinfo, int iseed, int ivalue, bool isHellfire);
void RecreateEar(ItemStruct &item, uint16_t ic, int iseed, int Id, int dur, int mdur, int ch, int mch, int ivalue, int ibuff);
void RecreateItem(Item &item, int idx, uint16_t icreateinfo, int iseed, int ivalue, bool isHellfire);
void RecreateEar(Item &item, uint16_t ic, int iseed, int Id, int dur, int mdur, int ch, int mch, int ivalue, int ibuff);
void CornerstoneSave();
void CornerstoneLoad(Point position);
void SpawnQuestItem(int itemid, Point position, int randarea, int selflag);
@ -442,20 +442,20 @@ void SpawnRewardItem(int itemid, Point position);
void SpawnMapOfDoom(Point position);
void SpawnRuneBomb(Point position);
void SpawnTheodore(Point position);
void RespawnItem(ItemStruct *item, bool FlipFlag);
void RespawnItem(Item *item, bool FlipFlag);
void DeleteItem(int ii, int i);
void ProcessItems();
void FreeItemGFX();
void GetItemFrm(ItemStruct &item);
void GetItemStr(ItemStruct &item);
void GetItemFrm(Item &item);
void GetItemStr(Item &item);
void CheckIdentify(Player &player, int cii);
void DoRepair(Player &player, int cii);
void DoRecharge(Player &player, int cii);
void DoOil(Player &player, int cii);
void PrintItemPower(char plidx, ItemStruct *x);
void PrintItemPower(char plidx, Item *x);
void DrawUniqueInfo(const Surface &out);
void PrintItemDetails(ItemStruct *x);
void PrintItemDur(ItemStruct *x);
void PrintItemDetails(Item *x);
void PrintItemDur(Item *x);
void UseItem(int p, item_misc_id Mid, spell_id spl);
void SpawnSmith(int lvl);
void SpawnPremium(int pnum);

14
Source/loadsave.cpp

@ -207,7 +207,7 @@ public:
}
};
void LoadItemData(LoadHelper *file, ItemStruct *pItem)
void LoadItemData(LoadHelper *file, Item *pItem)
{
pItem->_iSeed = file->NextLE<int32_t>();
pItem->_iCreateInfo = file->NextLE<uint16_t>();
@ -297,7 +297,7 @@ void LoadItemData(LoadHelper *file, ItemStruct *pItem)
RemoveInvalidItem(pItem);
}
void LoadItems(LoadHelper *file, const int n, ItemStruct *pItem)
void LoadItems(LoadHelper *file, const int n, Item *pItem)
{
for (int i = 0; i < n; i++) {
LoadItemData(file, &pItem[i]);
@ -843,9 +843,9 @@ void ConvertLevels()
leveltype = tmpLeveltype;
}
void LoadMatchingItems(LoadHelper *file, const int n, ItemStruct *pItem)
void LoadMatchingItems(LoadHelper *file, const int n, Item *pItem)
{
ItemStruct tempItem;
Item tempItem;
for (int i = 0; i < n; i++) {
LoadItemData(file, &tempItem);
@ -869,7 +869,7 @@ void RemoveEmptyLevelItems()
}
}
void SaveItem(SaveHelper *file, ItemStruct *pItem)
void SaveItem(SaveHelper *file, Item *pItem)
{
auto idx = pItem->IDidx;
if (!gbIsHellfire)
@ -962,7 +962,7 @@ void SaveItem(SaveHelper *file, ItemStruct *pItem)
file->WriteLE<uint32_t>(pItem->_iDamAcFlags);
}
void SaveItems(SaveHelper *file, ItemStruct *pItem, const int n)
void SaveItems(SaveHelper *file, Item *pItem, const int n)
{
for (int i = 0; i < n; i++) {
SaveItem(file, &pItem[i]);
@ -1438,7 +1438,7 @@ const int HellfireItemSaveSize = 372;
} // namespace
void RemoveInvalidItem(ItemStruct *pItem)
void RemoveInvalidItem(Item *pItem)
{
bool isInvalid = !IsItemAvailable(pItem->IDidx) || !IsUniqueAvailable(pItem->_iUid);

2
Source/loadsave.h

@ -12,7 +12,7 @@ namespace devilution {
extern bool gbIsHellfireSaveGame;
extern uint8_t giNumberOfLevels;
void RemoveInvalidItem(ItemStruct *pItem);
void RemoveInvalidItem(Item *pItem);
_item_indexes RemapItemIdxFromDiablo(_item_indexes i);
_item_indexes RemapItemIdxToDiablo(_item_indexes i);
_item_indexes RemapItemIdxFromSpawn(_item_indexes i);

2
Source/msg.h

@ -236,7 +236,7 @@ struct TCmdPItem {
uint16_t wCI;
/**
* Item identifier
* @see ItemStruct::_iSeed
* @see Item::_iSeed
*/
int32_t dwSeed;
uint8_t bId;

2
Source/objects.cpp

@ -2679,7 +2679,7 @@ bool OperateShrineGloomy(int pnum)
auto &player = Players[pnum];
// Increment armor class by 2 and decrements max damage by 1.
for (ItemStruct &item : PlayerItemsRange(player)) {
for (Item &item : PlayerItemsRange(player)) {
switch (item._itype) {
case ITYPE_SWORD:
case ITYPE_AXE:

8
Source/pack.cpp

@ -35,7 +35,7 @@ void VerifyGoldSeeds(Player &player)
} // namespace
void PackItem(PkItemStruct *id, const ItemStruct *is)
void PackItem(PkItemStruct *id, const Item *is)
{
memset(id, 0, sizeof(*id));
if (is->isEmpty()) {
@ -137,14 +137,14 @@ void PackPlayer(PlayerPack *pPack, const Player &player, bool manashield)
}
/**
* Expand a PkItemStruct in to a ItemStruct
* Expand a PkItemStruct in to a Item
*
* Note: last slot of item[MAXITEMS+1] used as temporary buffer
* find real name reference below, possibly [sizeof(item[])/sizeof(ItemStruct)]
* find real name reference below, possibly [sizeof(item[])/sizeof(Item)]
* @param is The source packed item
* @param id The distination item
*/
void UnPackItem(const PkItemStruct *is, ItemStruct *id, bool isHellfire)
void UnPackItem(const PkItemStruct *is, Item *id, bool isHellfire)
{
auto &item = Items[MAXITEMS];
auto idx = static_cast<_item_indexes>(SDL_SwapLE16(is->idx));

4
Source/pack.h

@ -81,7 +81,7 @@ struct PlayerPack {
void PackPlayer(PlayerPack *pPack, const Player &player, bool manashield);
void UnPackPlayer(const PlayerPack *pPack, Player &player, bool netSync);
void PackItem(PkItemStruct *id, const ItemStruct *is);
void UnPackItem(const PkItemStruct *is, ItemStruct *id, bool isHellfire);
void PackItem(PkItemStruct *id, const Item *is);
void UnPackItem(const PkItemStruct *is, Item *id, bool isHellfire);
} // namespace devilution

12
Source/player.cpp

@ -568,7 +568,7 @@ void StartSpell(int pnum, Direction d, int cx, int cy)
player._pVar4 = GetSpellLevel(pnum, player._pSpell);
}
void RespawnDeadItem(ItemStruct *itm, Point target)
void RespawnDeadItem(Item *itm, Point target)
{
if (ActiveItemCount >= MAXITEMS)
return;
@ -584,7 +584,7 @@ void RespawnDeadItem(ItemStruct *itm, Point target)
itm->_itype = ITYPE_NONE;
}
void DeadItem(Player &player, ItemStruct *itm, Displacement direction)
void DeadItem(Player &player, Item *itm, Displacement direction)
{
if (itm->isEmpty())
return;
@ -1399,7 +1399,7 @@ bool DoBlock(int pnum)
void DamageArmor(int pnum)
{
int a;
ItemStruct *pi;
Item *pi;
if (pnum != MyPlayerId) {
return;
@ -1540,7 +1540,7 @@ void CheckNewPath(int pnum, bool pmWillBeCalled)
MonsterStruct *monster;
Player *target;
ObjectStruct *object;
ItemStruct *item;
Item *item;
int targetId = player.destParam1;
@ -3049,7 +3049,7 @@ StartPlayerKill(int pnum, int earflag)
DropHalfPlayersGold(pnum);
if (earflag != -1) {
if (earflag != 0) {
ItemStruct ear;
Item ear;
SetPlrHandItem(ear, IDI_EAR);
strcpy(ear._iName, fmt::format(_("Ear of {:s}"), player._pName).c_str());
switch (player._pClass) {
@ -3092,7 +3092,7 @@ StartPlayerKill(int pnum, int earflag)
void StripTopGold(Player &player)
{
ItemStruct tmpItem = player.HoldItem;
Item tmpItem = player.HoldItem;
for (int i = 0; i < player._pNumInv; i++) {
if (player.InvList[i]._itype == ITYPE_GOLD) {

14
Source/player.h

@ -258,12 +258,12 @@ struct Player {
int _pHFrames;
int _pDFrames;
int _pBFrames;
ItemStruct InvBody[NUM_INVLOC];
ItemStruct InvList[NUM_INV_GRID_ELEM];
Item InvBody[NUM_INVLOC];
Item InvList[NUM_INV_GRID_ELEM];
int _pNumInv;
int8_t InvGrid[NUM_INV_GRID_ELEM];
ItemStruct SpdList[MAXBELTITEMS];
ItemStruct HoldItem;
Item SpdList[MAXBELTITEMS];
Item HoldItem;
int _pIMinDam;
int _pIMaxDam;
int _pIAC;
@ -322,9 +322,9 @@ struct Player {
* matching items were found.
*/
template <typename TPredicate>
const ItemStruct *GetMostValuableItem(const TPredicate &itemPredicate) const
const Item *GetMostValuableItem(const TPredicate &itemPredicate) const
{
const auto getMostValuableItem = [&itemPredicate](const ItemStruct *begin, const ItemStruct *end, const ItemStruct *mostValuableItem = nullptr) {
const auto getMostValuableItem = [&itemPredicate](const Item *begin, const Item *end, const Item *mostValuableItem = nullptr) {
for (const auto *item = begin; item < end; item++) {
if (item->isEmpty() || !itemPredicate(*item)) {
continue;
@ -338,7 +338,7 @@ struct Player {
return mostValuableItem;
};
const ItemStruct *mostValuableItem = getMostValuableItem(SpdList, SpdList + MAXBELTITEMS);
const Item *mostValuableItem = getMostValuableItem(SpdList, SpdList + MAXBELTITEMS);
mostValuableItem = getMostValuableItem(InvBody, InvBody + inv_body_loc::NUM_INVLOC, mostValuableItem);
mostValuableItem = getMostValuableItem(InvList, InvList + _pNumInv, mostValuableItem);

4
Source/qol/itemlabels.cpp

@ -63,7 +63,7 @@ void AddItemToLabelQueue(int id, int x, int y)
{
if (!IsHighlightingLabelsEnabled())
return;
ItemStruct &item = Items[id];
Item &item = Items[id];
const char *textOnGround;
if (item._itype == ITYPE_GOLD) {
@ -146,7 +146,7 @@ void DrawItemNameLabels(const Surface &out)
}
for (const ItemLabel &label : labelQueue) {
ItemStruct &item = Items[label.id];
Item &item = Items[label.id];
if (MousePosition.x >= label.pos.x && MousePosition.x < label.pos.x + label.width && MousePosition.y >= label.pos.y - Height + MarginY && MousePosition.y < label.pos.y + MarginY) {
if (!gmenu_is_active() && PauseMode == 0 && !MyPlayerIsDead && IsMouseOverGameArea()) {

30
Source/stores.cpp

@ -22,7 +22,7 @@
namespace devilution {
ItemStruct golditem;
Item golditem;
std::optional<CelSprite> pSTextBoxCels;
std::optional<CelSprite> pSTextSlidCels;
@ -31,19 +31,19 @@ talk_id stextflag;
int storenumh;
char storehidx[48];
ItemStruct storehold[48];
Item storehold[48];
ItemStruct smithitem[SMITH_ITEMS];
Item smithitem[SMITH_ITEMS];
int numpremium;
int premiumlevel;
ItemStruct premiumitems[SMITH_PREMIUM_ITEMS];
Item premiumitems[SMITH_PREMIUM_ITEMS];
ItemStruct healitem[20];
Item healitem[20];
ItemStruct witchitem[WITCH_ITEMS];
Item witchitem[WITCH_ITEMS];
int boylevel;
ItemStruct boyitem;
Item boyitem;
namespace {
@ -160,7 +160,7 @@ void AddSText(int x, int y, const char *str, UiFlags flags, bool sel)
stext[y]._ssel = sel;
}
void PrintStoreItem(ItemStruct *x, int l, UiFlags flags)
void PrintStoreItem(Item *x, int l, UiFlags flags)
{
char sstr[128];
@ -364,7 +364,7 @@ bool StartSmithPremiumBuy()
bool SmithSellOk(int i)
{
ItemStruct *pI;
Item *pI;
if (i >= 0) {
pI = &Players[MyPlayerId].InvList[i];
@ -668,7 +668,7 @@ void StartWitchBuy()
bool WitchSellOk(int i)
{
ItemStruct *pI;
Item *pI;
bool rv = false;
@ -782,7 +782,7 @@ bool WitchRechargeOk(int i)
return false;
}
void AddStoreHoldRecharge(ItemStruct itm, int8_t i)
void AddStoreHoldRecharge(Item itm, int8_t i)
{
storehold[storenumh] = itm;
storehold[storenumh]._ivalue += spelldata[itm._iSpell].sStaffCost;
@ -1057,7 +1057,7 @@ void StartStoryteller()
AddSLine(5);
}
bool IdItemOk(ItemStruct *i)
bool IdItemOk(Item *i)
{
if (i->isEmpty()) {
return false;
@ -1068,7 +1068,7 @@ bool IdItemOk(ItemStruct *i)
return !i->_iIdentified;
}
void AddStoreHoldId(ItemStruct itm, int8_t i)
void AddStoreHoldId(Item itm, int8_t i)
{
storehold[storenumh] = itm;
storehold[storenumh]._ivalue = 100;
@ -2174,9 +2174,9 @@ void DrawSelector(const Surface &out, const Rectangle &rect, const char *text, U
} // namespace
void AddStoreHoldRepair(ItemStruct *itm, int8_t i)
void AddStoreHoldRepair(Item *itm, int8_t i)
{
ItemStruct *item;
Item *item;
int v;
item = &storehold[storenumh];

16
Source/stores.h

@ -69,32 +69,32 @@ extern int storenumh;
/** Map of inventory items being presented in the store */
extern char storehidx[48];
/** Copies of the players items as presented in the store */
extern ItemStruct storehold[48];
extern Item storehold[48];
/** Temporary item used to generate gold piles by various function */
extern ItemStruct golditem;
extern Item golditem;
/** Items sold by Griswold */
extern ItemStruct smithitem[SMITH_ITEMS];
extern Item smithitem[SMITH_ITEMS];
/** Number of premium items for sale by Griswold */
extern int numpremium;
/** Base level of current premium items sold by Griswold */
extern int premiumlevel;
/** Premium items sold by Griswold */
extern ItemStruct premiumitems[SMITH_PREMIUM_ITEMS];
extern Item premiumitems[SMITH_PREMIUM_ITEMS];
/** Items sold by Pepin */
extern ItemStruct healitem[20];
extern Item healitem[20];
/** Items sold by Adria */
extern ItemStruct witchitem[WITCH_ITEMS];
extern Item witchitem[WITCH_ITEMS];
/** Current level of the item sold by Wirt */
extern int boylevel;
/** Current item sold by Wirt */
extern ItemStruct boyitem;
extern Item boyitem;
void AddStoreHoldRepair(ItemStruct *itm, int8_t i);
void AddStoreHoldRepair(Item *itm, int8_t i);
void InitStores();
void SetupTownStores();
void FreeStoreMem();

4
test/inv_test.cpp

@ -7,7 +7,7 @@
using namespace devilution;
/* Set up a given item as a spell scroll, allowing for its usage. */
void set_up_scroll(ItemStruct &item, spell_id spell)
void set_up_scroll(Item &item, spell_id spell)
{
pcurs = CURSOR_HAND;
leveltype = DTYPE_CATACOMBS;
@ -21,7 +21,7 @@ void set_up_scroll(ItemStruct &item, spell_id spell)
void clear_inventory()
{
for (int i = 0; i < NUM_INV_GRID_ELEM; i++) {
memset(&Players[MyPlayerId].InvList[i], 0, sizeof(ItemStruct));
memset(&Players[MyPlayerId].InvList[i], 0, sizeof(Item));
Players[MyPlayerId].InvGrid[i] = 0;
}
Players[MyPlayerId]._pNumInv = 0;

22
test/pack_test.cpp

@ -86,7 +86,7 @@ typedef struct TestItemStruct {
int IDidx;
} TestItemStruct;
static void CompareItems(const ItemStruct *item1, const TestItemStruct *item2)
static void CompareItems(const Item *item1, const TestItemStruct *item2)
{
ASSERT_STREQ(item1->_iIName, item2->_iIName);
EXPECT_EQ(item1->_itype, item2->_itype);
@ -328,7 +328,7 @@ const TestItemStruct DiabloItems[] = {
TEST(pack, UnPackItem_diablo)
{
ItemStruct id;
Item id;
PkItemStruct is;
gbIsHellfire = false;
@ -356,7 +356,7 @@ TEST(pack, UnPackItem_diablo_unique_bug)
gbIsMultiplayer = false;
gbIsSpawn = false;
ItemStruct id;
Item id;
UnPackItem(&pkItemBug, &id, false);
ASSERT_STREQ(id._iIName, "Veil of Steel");
ASSERT_EQ(id._itype, ITYPE_HELM);
@ -399,7 +399,7 @@ const TestItemStruct SpawnItems[] = {
TEST(pack, UnPackItem_spawn)
{
ItemStruct id;
Item id;
PkItemStruct is;
gbIsHellfire = false;
@ -443,7 +443,7 @@ const TestItemStruct DiabloMPItems[] = {
TEST(pack, UnPackItem_diablo_multiplayer)
{
ItemStruct id;
Item id;
PkItemStruct is;
gbIsHellfire = false;
@ -652,7 +652,7 @@ const TestItemStruct HellfireItems[] = {
TEST(pack, UnPackItem_hellfire)
{
ItemStruct id;
Item id;
PkItemStruct is;
gbIsHellfire = true;
@ -675,7 +675,7 @@ TEST(pack, UnPackItem_hellfire)
TEST(pack, UnPackItem_diablo_strip_hellfire_items)
{
PkItemStruct is = { 1478792102, 259, 92, 0, 0, 0, 0, 0, 0, 0 }; // Scroll of Search
ItemStruct id;
Item id;
gbIsHellfire = false;
gbIsMultiplayer = false;
@ -689,7 +689,7 @@ TEST(pack, UnPackItem_diablo_strip_hellfire_items)
TEST(pack, UnPackItem_empty)
{
PkItemStruct is = { 0, 0, 0xFFFF, 0, 0, 0, 0, 0, 0, 0 };
ItemStruct id;
Item id;
UnPackItem(&is, &id, false);
@ -699,7 +699,7 @@ TEST(pack, UnPackItem_empty)
TEST(pack, PackItem_empty)
{
PkItemStruct is;
ItemStruct id;
Item id;
id._itype = ITYPE_NONE;
@ -710,7 +710,7 @@ TEST(pack, PackItem_empty)
static void compareGold(const PkItemStruct *is, int iCurs)
{
ItemStruct id;
Item id;
UnPackItem(is, &id, false);
ASSERT_EQ(id._iCurs, iCurs);
ASSERT_EQ(id.IDidx, IDI_GOLD);
@ -744,7 +744,7 @@ TEST(pack, UnPackItem_gold_large)
TEST(pack, UnPackItem_ear)
{
PkItemStruct is = { 1633955154, 17509, 23, 111, 103, 117, 101, 68, 19843, 0 };
ItemStruct id;
Item id;
UnPackItem(&is, &id, false);
ASSERT_STREQ(id._iName, "Ear of Dead-RogueDM");

2
test/player_test.h

@ -10,7 +10,7 @@
using namespace devilution;
static int CountItems(ItemStruct *items, int n)
static int CountItems(Item *items, int n)
{
int count = n;
for (int i = 0; i < n; i++)

4
test/stores_test.cpp

@ -8,7 +8,7 @@ namespace {
TEST(Stores, AddStoreHoldRepair_magic)
{
ItemStruct *item;
Item *item;
item = &storehold[0];
@ -41,7 +41,7 @@ TEST(Stores, AddStoreHoldRepair_magic)
TEST(Stores, AddStoreHoldRepair_normal)
{
ItemStruct *item;
Item *item;
item = &storehold[0];

Loading…
Cancel
Save