Browse Source

Remove the use of HoldItem in AutoGetItem (#4178)

pull/4183/head
Andrew James 4 years ago committed by GitHub
parent
commit
4ff83431d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      Source/control.cpp
  2. 2
      Source/control.h
  3. 104
      Source/inv.cpp
  4. 1
      Source/inv.h
  5. 4
      Source/qol/stash.cpp

8
Source/control.cpp

@ -372,7 +372,7 @@ void RemoveGold(Player &player, int goldIndex)
SetGoldSeed(player, player.HoldItem); SetGoldSeed(player, player.HoldItem);
player.HoldItem._ivalue = dropGoldValue; player.HoldItem._ivalue = dropGoldValue;
player.HoldItem._iStatFlag = true; player.HoldItem._iStatFlag = true;
ControlSetGoldCurs(player); ControlSetGoldCurs(player.HoldItem);
player._pGold = CalculateGold(player); player._pGold = CalculateGold(player);
dropGoldValue = 0; dropGoldValue = 0;
} }
@ -397,10 +397,10 @@ bool IsLevelUpButtonVisible()
} // namespace } // namespace
void ControlSetGoldCurs(Player &player) void ControlSetGoldCurs(Item &goldItem)
{ {
SetPlrHandGoldCurs(player.HoldItem); SetPlrHandGoldCurs(goldItem);
NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); NewCursor(goldItem._iCurs + CURSOR_FIRSTITEM);
} }
void CalculatePanelAreas() void CalculatePanelAreas()

2
Source/control.h

@ -68,7 +68,7 @@ inline bool CanPanelsCoverView()
{ {
return GetScreenWidth() <= PANEL_WIDTH && GetScreenHeight() <= SPANEL_HEIGHT + PANEL_HEIGHT; return GetScreenWidth() <= PANEL_WIDTH && GetScreenHeight() <= SPANEL_HEIGHT + PANEL_HEIGHT;
} }
void ControlSetGoldCurs(Player &player); void ControlSetGoldCurs(Item &goldItem);
void DrawSpellList(const Surface &out); void DrawSpellList(const Surface &out);
void SetSpell(); void SetSpell();

104
Source/inv.cpp

@ -867,7 +867,7 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove, bool dropIt
} }
CalcPlrInv(player, true); CalcPlrInv(player, true);
CheckItemStats(player); holdItem._iStatFlag = player.CanUseItem(holdItem);
if (pnum == MyPlayerId) { if (pnum == MyPlayerId) {
if (automaticallyEquipped) { if (automaticallyEquipped) {
@ -910,26 +910,26 @@ void CheckInvCut(int pnum, Point cursorPosition, bool automaticMove, bool dropIt
} }
} }
void CheckBookLevel(Player &player) void UpdateBookLevel(Player &player, Item &book)
{ {
if (player.HoldItem._iMiscId != IMISC_BOOK) if (book._iMiscId != IMISC_BOOK)
return; return;
player.HoldItem._iMinMag = spelldata[player.HoldItem._iSpell].sMinInt; book._iMinMag = spelldata[book._iSpell].sMinInt;
int8_t spellLevel = player._pSplLvl[player.HoldItem._iSpell]; int8_t spellLevel = player._pSplLvl[book._iSpell];
while (spellLevel != 0) { while (spellLevel != 0) {
player.HoldItem._iMinMag += 20 * player.HoldItem._iMinMag / 100; book._iMinMag += 20 * book._iMinMag / 100;
spellLevel--; spellLevel--;
if (player.HoldItem._iMinMag + 20 * player.HoldItem._iMinMag / 100 > 255) { if (book._iMinMag + 20 * book._iMinMag / 100 > 255) {
player.HoldItem._iMinMag = -1; book._iMinMag = -1;
spellLevel = 0; spellLevel = 0;
} }
} }
} }
void CheckNaKrulNotes(Player &player) void TryCombineNaKrulNotes(Player &player, Item &noteItem)
{ {
int idx = player.HoldItem.IDidx; int idx = noteItem.IDidx;
_item_indexes notes[] = { IDI_NOTE1, IDI_NOTE2, IDI_NOTE3 }; _item_indexes notes[] = { IDI_NOTE1, IDI_NOTE2, IDI_NOTE3 };
if (IsNoneOf(idx, IDI_NOTE1, IDI_NOTE2, IDI_NOTE3)) { if (IsNoneOf(idx, IDI_NOTE1, IDI_NOTE2, IDI_NOTE3)) {
@ -950,24 +950,24 @@ void CheckNaKrulNotes(Player &player)
} }
} }
player.HoldItem = {}; noteItem = {};
GetItemAttrs(player.HoldItem, IDI_FULLNOTE, 16); GetItemAttrs(noteItem, IDI_FULLNOTE, 16);
SetupItem(player.HoldItem); SetupItem(noteItem);
} }
void CheckQuestItem(Player &player) void CheckQuestItem(Player &player, Item &questItem)
{ {
auto &myPlayer = Players[MyPlayerId]; auto &myPlayer = Players[MyPlayerId];
if (player.HoldItem.IDidx == IDI_OPTAMULET && Quests[Q_BLIND]._qactive == QUEST_ACTIVE) if (questItem.IDidx == IDI_OPTAMULET && Quests[Q_BLIND]._qactive == QUEST_ACTIVE)
Quests[Q_BLIND]._qactive = QUEST_DONE; Quests[Q_BLIND]._qactive = QUEST_DONE;
if (player.HoldItem.IDidx == IDI_MUSHROOM && Quests[Q_MUSHROOM]._qactive == QUEST_ACTIVE && Quests[Q_MUSHROOM]._qvar1 == QS_MUSHSPAWNED) { if (questItem.IDidx == IDI_MUSHROOM && Quests[Q_MUSHROOM]._qactive == QUEST_ACTIVE && Quests[Q_MUSHROOM]._qvar1 == QS_MUSHSPAWNED) {
player.Say(HeroSpeech::NowThatsOneBigMushroom, 10); // BUGFIX: Voice for this quest might be wrong in MP player.Say(HeroSpeech::NowThatsOneBigMushroom, 10); // BUGFIX: Voice for this quest might be wrong in MP
Quests[Q_MUSHROOM]._qvar1 = QS_MUSHPICKED; Quests[Q_MUSHROOM]._qvar1 = QS_MUSHPICKED;
} }
if (player.HoldItem.IDidx == IDI_ANVIL && Quests[Q_ANVIL]._qactive != QUEST_NOTAVAIL) { if (questItem.IDidx == IDI_ANVIL && Quests[Q_ANVIL]._qactive != QUEST_NOTAVAIL) {
if (Quests[Q_ANVIL]._qactive == QUEST_INIT) { if (Quests[Q_ANVIL]._qactive == QUEST_INIT) {
Quests[Q_ANVIL]._qactive = QUEST_ACTIVE; Quests[Q_ANVIL]._qactive = QUEST_ACTIVE;
} }
@ -976,11 +976,11 @@ void CheckQuestItem(Player &player)
} }
} }
if (player.HoldItem.IDidx == IDI_GLDNELIX && Quests[Q_VEIL]._qactive != QUEST_NOTAVAIL) { if (questItem.IDidx == IDI_GLDNELIX && Quests[Q_VEIL]._qactive != QUEST_NOTAVAIL) {
myPlayer.Say(HeroSpeech::INeedToGetThisToLachdanan, 30); myPlayer.Say(HeroSpeech::INeedToGetThisToLachdanan, 30);
} }
if (player.HoldItem.IDidx == IDI_ROCK && Quests[Q_ROCK]._qactive != QUEST_NOTAVAIL) { if (questItem.IDidx == IDI_ROCK && Quests[Q_ROCK]._qactive != QUEST_NOTAVAIL) {
if (Quests[Q_ROCK]._qactive == QUEST_INIT) { if (Quests[Q_ROCK]._qactive == QUEST_INIT) {
Quests[Q_ROCK]._qactive = QUEST_ACTIVE; Quests[Q_ROCK]._qactive = QUEST_ACTIVE;
} }
@ -989,12 +989,12 @@ void CheckQuestItem(Player &player)
} }
} }
if (player.HoldItem.IDidx == IDI_ARMOFVAL && Quests[Q_BLOOD]._qactive == QUEST_ACTIVE) { if (questItem.IDidx == IDI_ARMOFVAL && Quests[Q_BLOOD]._qactive == QUEST_ACTIVE) {
Quests[Q_BLOOD]._qactive = QUEST_DONE; Quests[Q_BLOOD]._qactive = QUEST_DONE;
myPlayer.Say(HeroSpeech::MayTheSpiritOfArkaineProtectMe, 20); myPlayer.Say(HeroSpeech::MayTheSpiritOfArkaineProtectMe, 20);
} }
if (player.HoldItem.IDidx == IDI_MAPOFDOOM) { if (questItem.IDidx == IDI_MAPOFDOOM) {
Quests[Q_GRAVE]._qlog = false; Quests[Q_GRAVE]._qlog = false;
Quests[Q_GRAVE]._qactive = QUEST_ACTIVE; Quests[Q_GRAVE]._qactive = QUEST_ACTIVE;
if (Quests[Q_GRAVE]._qvar1 != 1) { if (Quests[Q_GRAVE]._qvar1 != 1) {
@ -1003,7 +1003,7 @@ void CheckQuestItem(Player &player)
} }
} }
CheckNaKrulNotes(player); TryCombineNaKrulNotes(player, questItem);
} }
void OpenHive() void OpenHive()
@ -1151,7 +1151,6 @@ bool GoldAutoPlaceInInventorySlot(Player &player, int slotIndex, Item &goldStack
goldStack._ivalue = 0; goldStack._ivalue = 0;
player._pGold = CalculateGold(player); player._pGold = CalculateGold(player);
NewCursor(CURSOR_HAND);
return true; return true;
} }
@ -1603,13 +1602,6 @@ void CheckInvScrn(bool isShiftHeld, bool isCtrlHeld)
} }
} }
void CheckItemStats(Player &player)
{
Item &item = player.HoldItem;
item._iStatFlag = player.CanUseItem(item);
}
void InvGetItem(int pnum, int ii) void InvGetItem(int pnum, int ii)
{ {
auto &item = Items[ii]; auto &item = Items[ii];
@ -1628,9 +1620,9 @@ void InvGetItem(int pnum, int ii)
item._iCreateInfo &= ~CF_PREGEN; item._iCreateInfo &= ~CF_PREGEN;
player.HoldItem = item; player.HoldItem = item;
CheckQuestItem(player); CheckQuestItem(player, player.HoldItem);
CheckBookLevel(player); UpdateBookLevel(player, player.HoldItem);
CheckItemStats(player); player.HoldItem._iStatFlag = player.CanUseItem(player.HoldItem);
bool cursorUpdated = false; bool cursorUpdated = false;
if (player.HoldItem._itype == ItemType::Gold && GoldAutoPlace(player, player.HoldItem)) if (player.HoldItem._itype == ItemType::Gold && GoldAutoPlace(player, player.HoldItem))
cursorUpdated = true; cursorUpdated = true;
@ -1640,48 +1632,44 @@ void InvGetItem(int pnum, int ii)
NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM); NewCursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM);
} }
void AutoGetItem(int pnum, Item *item, int ii) void AutoGetItem(int pnum, Item *itemPointer, int ii)
{ {
bool done; Item &item = *itemPointer;
bool autoEquipped = false; auto &player = Players[pnum];
if (pcurs != CURSOR_HAND) {
return;
}
if (dropGoldFlag) { if (dropGoldFlag) {
CloseGoldDrop(); CloseGoldDrop();
dropGoldValue = 0; dropGoldValue = 0;
} }
if (dItem[item->position.x][item->position.y] == 0) if (dItem[item.position.x][item.position.y] == 0)
return; return;
auto &player = Players[pnum]; item._iCreateInfo &= ~CF_PREGEN;
CheckQuestItem(player, item);
UpdateBookLevel(player, item);
item._iStatFlag = player.CanUseItem(item);
SetICursor(item._iCurs + CURSOR_FIRSTITEM);
item->_iCreateInfo &= ~CF_PREGEN; bool done;
player.HoldItem = *item; /// BUGFIX: overwrites cursor item, allowing for belt dupe bug bool autoEquipped = false;
CheckQuestItem(player);
CheckBookLevel(player); if (item._itype == ItemType::Gold) {
CheckItemStats(player); done = GoldAutoPlace(player, item);
SetICursor(player.HoldItem._iCurs + CURSOR_FIRSTITEM);
if (player.HoldItem._itype == ItemType::Gold) {
done = GoldAutoPlace(player, player.HoldItem);
if (!done) { if (!done) {
item->_ivalue = player.HoldItem._ivalue; SetPlrHandGoldCurs(item);
SetPlrHandGoldCurs(*item);
} }
} else { } else {
done = AutoEquipEnabled(player, player.HoldItem) && AutoEquip(pnum, player.HoldItem); done = AutoEquipEnabled(player, item) && AutoEquip(pnum, item);
if (done) { if (done) {
autoEquipped = true; autoEquipped = true;
} }
if (!done) { if (!done) {
done = AutoPlaceItemInBelt(player, player.HoldItem, true); done = AutoPlaceItemInBelt(player, item, true);
} }
if (!done) { if (!done) {
done = AutoPlaceItemInInventory(player, player.HoldItem, true); done = AutoPlaceItemInInventory(player, item, true);
} }
} }
@ -1697,10 +1685,8 @@ void AutoGetItem(int pnum, Item *item, int ii)
if (pnum == MyPlayerId) { if (pnum == MyPlayerId) {
player.Say(HeroSpeech::ICantCarryAnymore); player.Say(HeroSpeech::ICantCarryAnymore);
} }
player.HoldItem = *item; RespawnItem(item, true);
RespawnItem(*item, true); NetSendCmdPItem(true, CMD_RESPAWNITEM, item.position, item);
NetSendCmdPItem(true, CMD_RESPAWNITEM, item->position, player.HoldItem);
player.HoldItem._itype = ItemType::None;
} }
int FindGetItem(int32_t iseed, _item_indexes idx, uint16_t createInfo) int FindGetItem(int32_t iseed, _item_indexes idx, uint16_t createInfo)

1
Source/inv.h

@ -168,7 +168,6 @@ void CheckInvItem(bool isShiftHeld = false, bool isCtrlHeld = false);
* Check for interactions with belt * Check for interactions with belt
*/ */
void CheckInvScrn(bool isShiftHeld, bool isCtrlHeld); void CheckInvScrn(bool isShiftHeld, bool isCtrlHeld);
void CheckItemStats(Player &player);
void InvGetItem(int pnum, int ii); void InvGetItem(int pnum, int ii);
void AutoGetItem(int pnum, Item *item, int ii); void AutoGetItem(int pnum, Item *item, int ii);

4
Source/qol/stash.cpp

@ -202,7 +202,7 @@ void CheckStashCut(Point cursorPosition, bool automaticMove, bool dropItem)
if (!holdItem.isEmpty()) { if (!holdItem.isEmpty()) {
CalcPlrInv(player, true); CalcPlrInv(player, true);
CheckItemStats(player); holdItem._iStatFlag = player.CanUseItem(holdItem);
if (automaticallyEquipped) { if (automaticallyEquipped) {
PlaySFX(ItemInvSnds[ItemCAnimTbl[holdItem._iCurs]]); PlaySFX(ItemInvSnds[ItemCAnimTbl[holdItem._iCurs]]);
} else if (!automaticMove || automaticallyMoved) { } else if (!automaticMove || automaticallyMoved) {
@ -266,7 +266,7 @@ void WithdrawGold(Player &player, int amount)
SetGoldSeed(player, player.HoldItem); SetGoldSeed(player, player.HoldItem);
player.HoldItem._ivalue = amount; player.HoldItem._ivalue = amount;
player.HoldItem._iStatFlag = true; player.HoldItem._iStatFlag = true;
ControlSetGoldCurs(player); ControlSetGoldCurs(player.HoldItem);
Stash.gold -= amount; Stash.gold -= amount;
Stash.dirty = true; Stash.dirty = true;
} }

Loading…
Cancel
Save