Browse Source

2435 refactor global variable Items part 2 (#2673)

pull/2712/head
BC Ko 5 years ago committed by GitHub
parent
commit
4df798808e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      Source/control.cpp
  2. 5
      Source/controls/plrctrls.cpp
  3. 2
      Source/debug.cpp
  4. 7
      Source/diablo.cpp
  5. 56
      Source/inv.cpp
  6. 634
      Source/items.cpp
  7. 16
      Source/items.h
  8. 2
      Source/loadsave.cpp
  9. 2
      Source/missiles.cpp
  10. 33
      Source/msg.cpp
  11. 10
      Source/objects.cpp
  12. 27
      Source/pack.cpp
  13. 14
      Source/player.cpp
  14. 5
      Source/qol/autopickup.cpp
  15. 20
      Source/qol/itemlabels.cpp
  16. 16
      Source/scrollrt.cpp
  17. 6
      Source/stores.cpp

26
Source/control.cpp

@ -444,14 +444,14 @@ int CapStatPointsToAdd(int remainingStatPoints, const PlayerStruct &player, Char
return std::min(remainingStatPoints, pointsToReachCap);
}
int DrawDurIcon4Item(const Surface &out, ItemStruct *pItem, int x, int c)
int DrawDurIcon4Item(const Surface &out, ItemStruct &pItem, int x, int c)
{
if (pItem->isEmpty())
if (pItem.isEmpty())
return x;
if (pItem->_iDurability > 5)
if (pItem._iDurability > 5)
return x;
if (c == 0) {
switch (pItem->_itype) {
switch (pItem._itype) {
case ITYPE_SWORD:
c = 2;
break;
@ -472,7 +472,7 @@ int DrawDurIcon4Item(const Surface &out, ItemStruct *pItem, int x, int c)
break;
}
}
if (pItem->_iDurability > 2)
if (pItem._iDurability > 2)
c += 8;
CelDrawTo(out, { x, -17 + PANEL_Y }, *pDurIcons, c);
return x - 32 - 8;
@ -512,7 +512,7 @@ spell_type GetSBookTrans(spell_id ii, bool townok)
void ControlSetGoldCurs(PlayerStruct &player)
{
SetPlrHandGoldCurs(&player.HoldItem);
SetPlrHandGoldCurs(player.HoldItem);
NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM);
}
@ -578,10 +578,10 @@ void RemoveGold(int pnum, int goldIndex)
int gi = goldIndex - INVITEM_INV_FIRST;
player.InvList[gi]._ivalue -= dropGoldValue;
if (player.InvList[gi]._ivalue > 0)
SetPlrHandGoldCurs(&player.InvList[gi]);
SetPlrHandGoldCurs(player.InvList[gi]);
else
player.RemoveInvItem(gi);
SetPlrHandItem(&player.HoldItem, IDI_GOLD);
SetPlrHandItem(player.HoldItem, IDI_GOLD);
GetGoldSeed(pnum, &player.HoldItem);
player.HoldItem._ivalue = dropGoldValue;
player.HoldItem._iStatFlag = true;
@ -1368,7 +1368,7 @@ void DrawInfoBox(const Surface &out)
}
} else {
if (pcursitem != -1)
GetItemStr(pcursitem);
GetItemStr(Items[pcursitem]);
else if (pcursobj != -1)
GetObjectStr(pcursobj);
if (pcursmonst != -1) {
@ -1729,10 +1729,10 @@ void DrawDurIcon(const Surface &out)
}
auto &myPlayer = Players[MyPlayerId];
x = DrawDurIcon4Item(out, &myPlayer.InvBody[INVLOC_HEAD], x, 4);
x = DrawDurIcon4Item(out, &myPlayer.InvBody[INVLOC_CHEST], x, 3);
x = DrawDurIcon4Item(out, &myPlayer.InvBody[INVLOC_HAND_LEFT], x, 0);
DrawDurIcon4Item(out, &myPlayer.InvBody[INVLOC_HAND_RIGHT], x, 0);
x = DrawDurIcon4Item(out, myPlayer.InvBody[INVLOC_HEAD], x, 4);
x = DrawDurIcon4Item(out, myPlayer.InvBody[INVLOC_CHEST], x, 3);
x = DrawDurIcon4Item(out, myPlayer.InvBody[INVLOC_HAND_LEFT], x, 0);
DrawDurIcon4Item(out, myPlayer.InvBody[INVLOC_HAND_RIGHT], x, 0);
}
void RedBack(const Surface &out)

5
Source/controls/plrctrls.cpp

@ -125,8 +125,9 @@ void FindItemOrObject()
if (dItem[mx + xx][my + yy] <= 0)
continue;
int i = dItem[mx + xx][my + yy] - 1;
if (Items[i].isEmpty()
|| Items[i]._iSelFlag == 0)
auto &item = Items[i];
if (item.isEmpty()
|| item._iSelFlag == 0)
continue;
int newRotations = GetRotaryDistance({ mx + xx, my + yy });
if (rotations < newRotations)

2
Source/debug.cpp

@ -116,7 +116,7 @@ std::string DebugCmdGiveGoldCheat(const std::string_view parameter)
continue;
int ni = myPlayer._pNumInv++;
SetPlrHandItem(&myPlayer.InvList[ni], IDI_GOLD);
SetPlrHandItem(myPlayer.InvList[ni], IDI_GOLD);
GetPlrHandSeed(&myPlayer.InvList[ni]);
myPlayer.InvList[ni]._ivalue = GOLD_MAX_LIMIT;
myPlayer.InvList[ni]._iCurs = ICURS_GOLD_LARGE;

7
Source/diablo.cpp

@ -1238,13 +1238,14 @@ void HelpKeyPressed()
#ifdef _DEBUG
void ItemInfoKeyPressed()
{
auto &item = Items[pcursitem];
if (pcursitem != -1) {
sprintf(
tempstr,
"IDX = %i : Seed = %i : CF = %i",
Items[pcursitem].IDidx,
Items[pcursitem]._iSeed,
Items[pcursitem]._iCreateInfo);
item.IDidx,
item._iSeed,
item._iCreateInfo);
NetSendCmdString(1 << MyPlayerId, tempstr);
}
sprintf(tempstr, "Numitems : %i", ActiveItemCount);

56
Source/inv.cpp

@ -610,7 +610,7 @@ void CheckInvPaste(int pnum, Point cursorPosition)
if (ig <= MaxGold) {
player.InvList[invIndex]._ivalue = ig;
player._pGold += player.HoldItem._ivalue;
SetPlrHandGoldCurs(&player.InvList[invIndex]);
SetPlrHandGoldCurs(player.InvList[invIndex]);
} else {
ig = MaxGold - gt;
player._pGold += ig;
@ -627,7 +627,7 @@ void CheckInvPaste(int pnum, Point cursorPosition)
player._pNumInv++;
player.InvGrid[ii] = player._pNumInv;
player._pGold += player.HoldItem._ivalue;
SetPlrHandGoldCurs(&player.InvList[invIndex]);
SetPlrHandGoldCurs(player.InvList[invIndex]);
}
} else {
if (it == 0) {
@ -939,8 +939,8 @@ void CheckNaKrulNotes(PlayerStruct &player)
int itemNum = ActiveItems[0];
ItemStruct tmp = Items[itemNum];
memset(&Items[itemNum], 0, sizeof(*Items));
GetItemAttrs(itemNum, IDI_FULLNOTE, 16);
SetupItem(itemNum);
GetItemAttrs(Items[itemNum], IDI_FULLNOTE, 16);
SetupItem(Items[itemNum]);
player.HoldItem = Items[itemNum];
Items[itemNum] = tmp;
}
@ -1468,7 +1468,7 @@ bool GoldAutoPlace(PlayerStruct &player)
player.InvList[i]._ivalue += player.HoldItem._ivalue;
if (player.InvList[i]._ivalue > MaxGold) {
player.HoldItem._ivalue = player.InvList[i]._ivalue - MaxGold;
SetPlrHandGoldCurs(&player.HoldItem);
SetPlrHandGoldCurs(player.HoldItem);
player.InvList[i]._ivalue = MaxGold;
if (gbIsHellfire)
GetPlrHandSeed(&player.HoldItem);
@ -1477,7 +1477,7 @@ bool GoldAutoPlace(PlayerStruct &player)
done = true;
}
SetPlrHandGoldCurs(&player.InvList[i]);
SetPlrHandGoldCurs(player.InvList[i]);
player._pGold = CalculateGold(player);
}
@ -1523,12 +1523,13 @@ bool GoldAutoPlaceInInventorySlot(PlayerStruct &player, int slotIndex)
void CheckInvSwap(int pnum, BYTE bLoc, int idx, uint16_t wCI, int seed, bool bId, uint32_t dwBuff)
{
memset(&Items[MAXITEMS], 0, sizeof(*Items));
RecreateItem(MAXITEMS, idx, wCI, seed, 0, (dwBuff & CF_HELLFIRE) != 0);
auto &item = Items[MAXITEMS];
memset(&item, 0, sizeof(item));
RecreateItem(item, idx, wCI, seed, 0, (dwBuff & CF_HELLFIRE) != 0);
auto &player = Players[pnum];
player.HoldItem = Items[MAXITEMS];
player.HoldItem = item;
if (bId) {
player.HoldItem._iIdentified = true;
@ -1648,7 +1649,7 @@ void AutoGetItem(int pnum, ItemStruct *item, int ii)
done = GoldAutoPlace(player);
if (!done) {
item->_ivalue = player.HoldItem._ivalue;
SetPlrHandGoldCurs(item);
SetPlrHandGoldCurs(*item);
}
} else {
done = AutoEquipEnabled(player, player.HoldItem) && AutoEquip(pnum, player.HoldItem);
@ -1835,29 +1836,30 @@ int SyncPutItem(PlayerStruct &player, Point position, int idx, uint16_t icreatei
assert(CanPut(position));
int ii = AllocateItem();
auto &item = Items[ii];
dItem[position.x][position.y] = ii + 1;
if (idx == IDI_EAR) {
RecreateEar(ii, icreateinfo, iseed, id, dur, mdur, ch, mch, ivalue, ibuff);
RecreateEar(item, icreateinfo, iseed, id, dur, mdur, ch, mch, ivalue, ibuff);
} else {
RecreateItem(ii, idx, icreateinfo, iseed, ivalue, (ibuff & CF_HELLFIRE) != 0);
RecreateItem(item, idx, icreateinfo, iseed, ivalue, (ibuff & CF_HELLFIRE) != 0);
if (id != 0)
Items[ii]._iIdentified = true;
Items[ii]._iDurability = dur;
Items[ii]._iMaxDur = mdur;
Items[ii]._iCharges = ch;
Items[ii]._iMaxCharges = mch;
Items[ii]._iPLToHit = toHit;
Items[ii]._iMaxDam = maxDam;
Items[ii]._iMinStr = minStr;
Items[ii]._iMinMag = minMag;
Items[ii]._iMinDex = minDex;
Items[ii]._iAC = ac;
Items[ii].dwBuff = ibuff;
}
Items[ii].position = position;
item._iIdentified = true;
item._iDurability = dur;
item._iMaxDur = mdur;
item._iCharges = ch;
item._iMaxCharges = mch;
item._iPLToHit = toHit;
item._iMaxDam = maxDam;
item._iMinStr = minStr;
item._iMinMag = minMag;
item._iMinDex = minDex;
item._iAC = ac;
item.dwBuff = ibuff;
}
item.position = position;
RespawnItem(&Items[ii], true);
if (currlevel == 21 && position == CornerStone.position) {

634
Source/items.cpp

File diff suppressed because it is too large Load Diff

16
Source/items.h

@ -411,25 +411,25 @@ void InitItemGFX();
void InitItems();
void CalcPlrItemVals(int p, bool Loadgfx);
void CalcPlrInv(int p, bool Loadgfx);
void SetPlrHandItem(ItemStruct *h, int idata);
void SetPlrHandItem(ItemStruct &item, int itemData);
void GetPlrHandSeed(ItemStruct *h);
void GetGoldSeed(int pnum, ItemStruct *h);
int GetGoldCursor(int value);
void SetPlrHandGoldCurs(ItemStruct *h);
void SetPlrHandGoldCurs(ItemStruct &gold);
void CreatePlrItems(int playerId);
bool ItemSpaceOk(Point position);
int AllocateItem();
Point GetSuperItemLoc(Point position);
void GetItemAttrs(int i, int idata, int lvl);
void SetupItem(int i);
void GetItemAttrs(ItemStruct &item, int itemData, int lvl);
void SetupItem(ItemStruct &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(int ii, int idx, uint16_t icreateinfo, int iseed, int ivalue, bool isHellfire);
void RecreateEar(int ii, uint16_t ic, int iseed, int Id, int dur, int mdur, int ch, int mch, int ivalue, int ibuff);
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 CornerstoneSave();
void CornerstoneLoad(Point position);
void SpawnQuestItem(int itemid, Point position, int randarea, int selflag);
@ -441,8 +441,8 @@ void RespawnItem(ItemStruct *item, bool FlipFlag);
void DeleteItem(int ii, int i);
void ProcessItems();
void FreeItemGFX();
void GetItemFrm(int i);
void GetItemStr(int i);
void GetItemFrm(ItemStruct &item);
void GetItemStr(ItemStruct &item);
void CheckIdentify(int pnum, int cii);
void DoRepair(int pnum, int cii);
void DoRecharge(int pnum, int cii);

2
Source/loadsave.cpp

@ -728,7 +728,7 @@ void LoadObject(LoadHelper *file, int i)
void LoadItem(LoadHelper *file, int i)
{
LoadItemData(file, &Items[i]);
GetItemFrm(i);
GetItemFrm(Items[i]);
}
void LoadPremium(LoadHelper *file, int i)

2
Source/missiles.cpp

@ -1516,7 +1516,7 @@ void AddStealPotions(MissileStruct &missile, Point /*dst*/, Direction /*midir*/)
}
}
if (ii != -1) {
SetPlrHandItem(&player.HoldItem, ii);
SetPlrHandItem(player.HoldItem, ii);
GetPlrHandSeed(&player.HoldItem);
player.HoldItem._iStatFlag = true;
player.SpdList[si] = player.HoldItem;

33
Source/msg.cpp

@ -2082,10 +2082,11 @@ void DeltaLoadLevel()
}
if (sgLevels[currlevel].item[i].bCmd == CMD_ACK_PLRINFO) {
int ii = AllocateItem();
auto &item = Items[ii];
if (sgLevels[currlevel].item[i].wIndx == IDI_EAR) {
RecreateEar(
ii,
item,
sgLevels[currlevel].item[i].wCI,
sgLevels[currlevel].item[i].dwSeed,
sgLevels[currlevel].item[i].bId,
@ -2097,30 +2098,30 @@ void DeltaLoadLevel()
sgLevels[currlevel].item[i].dwBuff);
} else {
RecreateItem(
ii,
item,
sgLevels[currlevel].item[i].wIndx,
sgLevels[currlevel].item[i].wCI,
sgLevels[currlevel].item[i].dwSeed,
sgLevels[currlevel].item[i].wValue,
(sgLevels[currlevel].item[i].dwBuff & CF_HELLFIRE) != 0);
if (sgLevels[currlevel].item[i].bId != 0)
Items[ii]._iIdentified = true;
Items[ii]._iDurability = sgLevels[currlevel].item[i].bDur;
Items[ii]._iMaxDur = sgLevels[currlevel].item[i].bMDur;
Items[ii]._iCharges = sgLevels[currlevel].item[i].bCh;
Items[ii]._iMaxCharges = sgLevels[currlevel].item[i].bMCh;
Items[ii]._iPLToHit = sgLevels[currlevel].item[i].wToHit;
Items[ii]._iMaxDam = sgLevels[currlevel].item[i].wMaxDam;
Items[ii]._iMinStr = sgLevels[currlevel].item[i].bMinStr;
Items[ii]._iMinMag = sgLevels[currlevel].item[i].bMinMag;
Items[ii]._iMinDex = sgLevels[currlevel].item[i].bMinDex;
Items[ii]._iAC = sgLevels[currlevel].item[i].bAC;
Items[ii].dwBuff = sgLevels[currlevel].item[i].dwBuff;
item._iIdentified = true;
item._iDurability = sgLevels[currlevel].item[i].bDur;
item._iMaxDur = sgLevels[currlevel].item[i].bMDur;
item._iCharges = sgLevels[currlevel].item[i].bCh;
item._iMaxCharges = sgLevels[currlevel].item[i].bMCh;
item._iPLToHit = sgLevels[currlevel].item[i].wToHit;
item._iMaxDam = sgLevels[currlevel].item[i].wMaxDam;
item._iMinStr = sgLevels[currlevel].item[i].bMinStr;
item._iMinMag = sgLevels[currlevel].item[i].bMinMag;
item._iMinDex = sgLevels[currlevel].item[i].bMinDex;
item._iAC = sgLevels[currlevel].item[i].bAC;
item.dwBuff = sgLevels[currlevel].item[i].dwBuff;
}
int x = sgLevels[currlevel].item[i].x;
int y = sgLevels[currlevel].item[i].y;
Items[ii].position = GetItemPosition({ x, y });
dItem[Items[ii].position.x][Items[ii].position.y] = ii + 1;
item.position = GetItemPosition({ x, y });
dItem[item.position.x][item.position.y] = ii + 1;
RespawnItem(&Items[ii], false);
}
}

10
Source/objects.cpp

@ -2977,14 +2977,14 @@ bool OperateShrineEldritch(int pnum)
if (player.InvList[j]._itype == ITYPE_MISC) {
if (player.InvList[j]._iMiscId == IMISC_HEAL
|| player.InvList[j]._iMiscId == IMISC_MANA) {
SetPlrHandItem(&player.HoldItem, ItemMiscIdIdx(IMISC_REJUV));
SetPlrHandItem(player.HoldItem, ItemMiscIdIdx(IMISC_REJUV));
GetPlrHandSeed(&player.HoldItem);
player.HoldItem._iStatFlag = true;
player.InvList[j] = player.HoldItem;
}
if (player.InvList[j]._iMiscId == IMISC_FULLHEAL
|| player.InvList[j]._iMiscId == IMISC_FULLMANA) {
SetPlrHandItem(&player.HoldItem, ItemMiscIdIdx(IMISC_FULLREJUV));
SetPlrHandItem(player.HoldItem, ItemMiscIdIdx(IMISC_FULLREJUV));
GetPlrHandSeed(&player.HoldItem);
player.HoldItem._iStatFlag = true;
player.InvList[j] = player.HoldItem;
@ -2995,14 +2995,14 @@ bool OperateShrineEldritch(int pnum)
if (item._itype == ITYPE_MISC) {
if (item._iMiscId == IMISC_HEAL
|| item._iMiscId == IMISC_MANA) {
SetPlrHandItem(&player.HoldItem, ItemMiscIdIdx(IMISC_REJUV));
SetPlrHandItem(player.HoldItem, ItemMiscIdIdx(IMISC_REJUV));
GetPlrHandSeed(&player.HoldItem);
player.HoldItem._iStatFlag = true;
item = player.HoldItem;
}
if (item._iMiscId == IMISC_FULLHEAL
|| item._iMiscId == IMISC_FULLMANA) {
SetPlrHandItem(&player.HoldItem, ItemMiscIdIdx(IMISC_FULLREJUV));
SetPlrHandItem(player.HoldItem, ItemMiscIdIdx(IMISC_FULLREJUV));
GetPlrHandSeed(&player.HoldItem);
player.HoldItem._iStatFlag = true;
item = player.HoldItem;
@ -3151,7 +3151,7 @@ bool OperateShrineSpiritual(int pnum)
gridItem = player._pNumInv;
player.InvList[t]._ivalue = r;
player._pGold += r;
SetPlrHandGoldCurs(&player.InvList[t]);
SetPlrHandGoldCurs(player.InvList[t]);
}
}

27
Source/pack.cpp

@ -146,6 +146,7 @@ void PackPlayer(PkPlayerStruct *pPack, const PlayerStruct &player, bool manashie
*/
void UnPackItem(const PkItemStruct *is, ItemStruct *id, bool isHellfire)
{
auto &item = Items[MAXITEMS];
auto idx = static_cast<_item_indexes>(SDL_SwapLE16(is->idx));
if (idx == IDI_NONE) {
id->_itype = ITYPE_NONE;
@ -166,7 +167,7 @@ void UnPackItem(const PkItemStruct *is, ItemStruct *id, bool isHellfire)
if (idx == IDI_EAR) {
RecreateEar(
MAXITEMS,
item,
SDL_SwapLE16(is->iCreateInfo),
SDL_SwapLE32(is->iSeed),
is->bId,
@ -177,23 +178,23 @@ void UnPackItem(const PkItemStruct *is, ItemStruct *id, bool isHellfire)
SDL_SwapLE16(is->wValue),
SDL_SwapLE32(is->dwBuff));
} else {
memset(&Items[MAXITEMS], 0, sizeof(*Items));
RecreateItem(MAXITEMS, idx, SDL_SwapLE16(is->iCreateInfo), SDL_SwapLE32(is->iSeed), SDL_SwapLE16(is->wValue), isHellfire);
Items[MAXITEMS]._iMagical = static_cast<item_quality>(is->bId >> 1);
Items[MAXITEMS]._iIdentified = (is->bId & 1) != 0;
Items[MAXITEMS]._iDurability = is->bDur;
Items[MAXITEMS]._iMaxDur = is->bMDur;
Items[MAXITEMS]._iCharges = is->bCh;
Items[MAXITEMS]._iMaxCharges = is->bMCh;
memset(&item, 0, sizeof(item));
RecreateItem(item, idx, SDL_SwapLE16(is->iCreateInfo), SDL_SwapLE32(is->iSeed), SDL_SwapLE16(is->wValue), isHellfire);
item._iMagical = static_cast<item_quality>(is->bId >> 1);
item._iIdentified = (is->bId & 1) != 0;
item._iDurability = is->bDur;
item._iMaxDur = is->bMDur;
item._iCharges = is->bCh;
item._iMaxCharges = is->bMCh;
RemoveInvalidItem(&Items[MAXITEMS]);
RemoveInvalidItem(&item);
if (isHellfire)
Items[MAXITEMS].dwBuff |= CF_HELLFIRE;
item.dwBuff |= CF_HELLFIRE;
else
Items[MAXITEMS].dwBuff &= ~CF_HELLFIRE;
item.dwBuff &= ~CF_HELLFIRE;
}
*id = Items[MAXITEMS];
*id = item;
}
void UnPackPlayer(const PkPlayerStruct *pPack, int pnum, bool netSync)

14
Source/player.cpp

@ -624,9 +624,9 @@ int DropGold(int pnum, int amount, bool skipFullStacks)
if (amount < item._ivalue) {
item._ivalue -= amount;
SetPlrHandItem(&player.HoldItem, IDI_GOLD);
SetPlrHandItem(player.HoldItem, IDI_GOLD);
GetGoldSeed(pnum, &player.HoldItem);
SetPlrHandGoldCurs(&player.HoldItem);
SetPlrHandGoldCurs(player.HoldItem);
player.HoldItem._ivalue = amount;
DeadItem(player, &player.HoldItem, { 0, 0 });
return 0;
@ -634,9 +634,9 @@ int DropGold(int pnum, int amount, bool skipFullStacks)
amount -= item._ivalue;
player.RemoveInvItem(i);
SetPlrHandItem(&player.HoldItem, IDI_GOLD);
SetPlrHandItem(player.HoldItem, IDI_GOLD);
GetGoldSeed(pnum, &player.HoldItem);
SetPlrHandGoldCurs(&player.HoldItem);
SetPlrHandGoldCurs(player.HoldItem);
player.HoldItem._ivalue = item._ivalue;
DeadItem(player, &player.HoldItem, { 0, 0 });
i = -1;
@ -3076,7 +3076,7 @@ StartPlayerKill(int pnum, int earflag)
if (earflag != -1) {
if (earflag != 0) {
ItemStruct ear;
SetPlrHandItem(&ear, IDI_EAR);
SetPlrHandItem(ear, IDI_EAR);
strcpy(ear._iName, fmt::format(_("Ear of {:s}"), player._pName).c_str());
switch (player._pClass) {
case HeroClass::Sorcerer:
@ -3130,10 +3130,10 @@ void StripTopGold(int pnum)
if (player.InvList[i]._ivalue > MaxGold) {
int val = player.InvList[i]._ivalue - MaxGold;
player.InvList[i]._ivalue = MaxGold;
SetPlrHandItem(&player.HoldItem, 0);
SetPlrHandItem(player.HoldItem, 0);
GetGoldSeed(pnum, &player.HoldItem);
player.HoldItem._ivalue = val;
SetPlrHandGoldCurs(&player.HoldItem);
SetPlrHandGoldCurs(player.HoldItem);
if (!GoldAutoPlace(player))
DeadItem(player, &player.HoldItem, { 0, 0 });
}

5
Source/qol/autopickup.cpp

@ -48,9 +48,10 @@ void AutoGoldPickup(int pnum)
Point tile = Players[pnum].position.tile + pathDir;
if (dItem[tile.x][tile.y] != 0) {
int itemIndex = dItem[tile.x][tile.y] - 1;
if (Items[itemIndex]._itype == ITYPE_GOLD) {
auto &item = Items[itemIndex];
if (item._itype == ITYPE_GOLD) {
NetSendCmdGItem(true, CMD_REQUESTAGITEM, pnum, pnum, itemIndex);
Items[itemIndex]._iRequest = true;
item._iRequest = true;
PlaySFX(IS_IGRAB);
}
}

20
Source/qol/itemlabels.cpp

@ -63,21 +63,21 @@ void AddItemToLabelQueue(int id, int x, int y)
{
if (!IsHighlightingLabelsEnabled())
return;
ItemStruct *it = &Items[id];
ItemStruct &item = Items[id];
const char *textOnGround;
if (it->_itype == ITYPE_GOLD) {
std::sprintf(tempstr, _("%i gold"), it->_ivalue);
if (item._itype == ITYPE_GOLD) {
std::sprintf(tempstr, _("%i gold"), item._ivalue);
textOnGround = tempstr;
} else {
textOnGround = it->_iIdentified ? it->_iIName : it->_iName;
textOnGround = item._iIdentified ? item._iIName : item._iName;
}
int nameWidth = GetLineWidth(textOnGround);
nameWidth += MarginX * 2;
int index = ItemCAnimTbl[it->_iCurs];
int index = ItemCAnimTbl[item._iCurs];
if (!labelCenterOffsets[index]) {
std::pair<int, int> itemBounds = MeasureSolidHorizontalBounds(*it->AnimInfo.pCelSprite, it->AnimInfo.CurrentFrame);
std::pair<int, int> itemBounds = MeasureSolidHorizontalBounds(*item.AnimInfo.pCelSprite, item.AnimInfo.CurrentFrame);
labelCenterOffsets[index].emplace((itemBounds.first + itemBounds.second) / 2);
}
@ -146,13 +146,13 @@ void DrawItemNameLabels(const Surface &out)
}
for (const ItemLabel &label : labelQueue) {
ItemStruct &itm = Items[label.id];
ItemStruct &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()) {
isLabelHighlighted = true;
cursmx = itm.position.x;
cursmy = itm.position.y;
cursmx = item.position.x;
cursmy = item.position.y;
pcursitem = label.id;
}
}
@ -160,7 +160,7 @@ void DrawItemNameLabels(const Surface &out)
FillRect(out, label.pos.x, label.pos.y - Height + MarginY, label.width, Height, PAL8_BLUE + 6);
else
DrawHalfTransparentRectTo(out, label.pos.x, label.pos.y - Height + MarginY, label.width, Height);
DrawString(out, label.text, { { label.pos.x + MarginX, label.pos.y }, { label.width, Height } }, itm.getTextColor());
DrawString(out, label.text, { { label.pos.x + MarginX, label.pos.y }, { label.width, Height } }, item.getTextColor());
}
labelQueue.clear();
}

16
Source/scrollrt.cpp

@ -679,30 +679,30 @@ void DrawItem(const Surface &out, int x, int y, int sx, int sy, bool pre)
if (bItem <= 0)
return;
ItemStruct *pItem = &Items[bItem - 1];
if (pItem->_iPostDraw == pre)
auto &item = Items[bItem - 1];
if (item._iPostDraw == pre)
return;
const auto *cel = pItem->AnimInfo.pCelSprite;
const auto *cel = item.AnimInfo.pCelSprite;
if (cel == nullptr) {
Log("Draw Item \"{}\" 1: NULL CelSprite", pItem->_iIName);
Log("Draw Item \"{}\" 1: NULL CelSprite", item._iIName);
return;
}
int nCel = pItem->AnimInfo.GetFrameToUseForRendering();
int nCel = item.AnimInfo.GetFrameToUseForRendering();
int frames = SDL_SwapLE32(*(DWORD *)cel->Data());
if (nCel < 1 || frames > 50 || nCel > frames) {
Log("Draw \"{}\" Item 1: frame {} of {}, item type=={}", pItem->_iIName, nCel, frames, pItem->_itype);
Log("Draw \"{}\" Item 1: frame {} of {}, item type=={}", item._iIName, nCel, frames, item._itype);
return;
}
int px = sx - CalculateWidth2(cel->Width());
const Point position { px, sy };
if (bItem - 1 == pcursitem || AutoMapShowItems) {
CelBlitOutlineTo(out, GetOutlineColor(*pItem, false), position, *cel, nCel);
CelBlitOutlineTo(out, GetOutlineColor(item, false), position, *cel, nCel);
}
CelClippedDrawLightTo(out, position, *cel, nCel);
if (pItem->AnimInfo.CurrentFrame == pItem->AnimInfo.NumberOfFrames || pItem->_iCurs == ICURS_MAGIC_ROCK)
if (item.AnimInfo.CurrentFrame == item.AnimInfo.NumberOfFrames || item._iCurs == ICURS_MAGIC_ROCK)
AddItemToLabelQueue(bItem - 1, px, sy);
}

6
Source/stores.cpp

@ -1474,7 +1474,7 @@ void PlaceStoreGold(int v)
myPlayer._pNumInv++;
gridNum = myPlayer._pNumInv;
myPlayer.InvList[ii]._ivalue = v;
SetPlrHandGoldCurs(&myPlayer.InvList[ii]);
SetPlrHandGoldCurs(myPlayer.InvList[ii]);
return;
}
}
@ -1513,7 +1513,7 @@ void StoreSellItem()
cost -= MaxGold - item._ivalue;
item._ivalue = MaxGold;
}
SetPlrHandGoldCurs(&myPlayer.InvList[i]);
SetPlrHandGoldCurs(myPlayer.InvList[i]);
}
}
if (cost > 0) {
@ -2140,7 +2140,7 @@ int TakeGold(PlayerStruct &player, int cost, bool skipMaxPiles)
if (cost < item._ivalue) {
item._ivalue -= cost;
SetPlrHandGoldCurs(&player.InvList[i]);
SetPlrHandGoldCurs(player.InvList[i]);
return 0;
}

Loading…
Cancel
Save