diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index b05b18bbc..12f48a6d5 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -15,10 +15,10 @@ #include "gmenu.h" #include "help.h" #include "inv.h" +#include "items.h" #include "minitext.h" #include "missiles.h" #include "stores.h" -#include "town.h" #include "towners.h" #include "trigs.h" @@ -1399,25 +1399,16 @@ bool TryDropItem() return false; } - if (myPlayer.HoldItem.IDidx == IDI_RUNEBOMB) { - for (auto dir : PathDirs) { - Point position = myPlayer.position.tile + dir; - if (OpensHive(position)) { - NetSendCmdPItem(true, CMD_PUTITEM, { 79, 61 }); - NewCursor(CURSOR_HAND); - return true; - } + if (currlevel == 0) { + if (UseItemOpensHive(myPlayer.HoldItem, myPlayer.position.tile)) { + NetSendCmdPItem(true, CMD_PUTITEM, { 79, 61 }); + NewCursor(CURSOR_HAND); + return true; } - } - - if (myPlayer.HoldItem.IDidx == IDI_MAPOFDOOM) { - for (auto dir : PathDirs) { - Point position = myPlayer.position.tile + dir; - if (OpensGrave(position)) { - NetSendCmdPItem(true, CMD_PUTITEM, { 35, 20 }); - NewCursor(CURSOR_HAND); - return true; - } + if (UseItemOpensCrypt(myPlayer.HoldItem, myPlayer.position.tile)) { + NetSendCmdPItem(true, CMD_PUTITEM, { 35, 20 }); + NewCursor(CURSOR_HAND); + return true; } } diff --git a/Source/inv.cpp b/Source/inv.cpp index 35cc42ce1..6c8f3e1ea 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -992,6 +992,24 @@ void CheckQuestItem(Player &player) CheckNaKrulNotes(player); } +void OpenHive() +{ + NetSendCmd(false, CMD_OPENHIVE); + auto &quest = Quests[Q_FARMER]; + quest._qactive = QUEST_DONE; + if (gbIsMultiplayer) + NetSendCmdQuest(true, quest); +} + +void OpenCrypt() +{ + NetSendCmd(false, CMD_OPENCRYPT); + auto &quest = Quests[Q_GRAVE]; + quest._qactive = QUEST_DONE; + if (gbIsMultiplayer) + NetSendCmdQuest(true, quest); +} + void CleanupItems(Item *item, int ii) { dItem[item->position.x][item->position.y] = 0; @@ -1725,19 +1743,11 @@ int InvPutItem(Player &player, Point position) { if (player.plrlevel == 0) { if (player.HoldItem.IDidx == IDI_RUNEBOMB && OpensHive(position)) { - NetSendCmd(false, CMD_OPENHIVE); - auto &quest = Quests[Q_FARMER]; - quest._qactive = QUEST_DONE; - if (gbIsMultiplayer) - NetSendCmdQuest(true, quest); + OpenHive(); return -1; } if (player.HoldItem.IDidx == IDI_MAPOFDOOM && OpensGrave(position)) { - NetSendCmd(false, CMD_OPENCRYPT); - auto &quest = Quests[Q_GRAVE]; - quest._qactive = QUEST_DONE; - if (gbIsMultiplayer) - NetSendCmdQuest(true, quest); + OpenCrypt(); return -1; } } @@ -2006,6 +2016,19 @@ bool UseInvItem(int pnum, int cii) return true; } + if (player.plrlevel == 0) { + if (UseItemOpensHive(*item, player.position.tile)) { + OpenHive(); + player.RemoveInvItem(c); + return true; + } + if (UseItemOpensCrypt(*item, player.position.tile)) { + OpenCrypt(); + player.RemoveInvItem(c); + return true; + } + } + if (!AllItemsList[item->IDidx].iUsable) return false; diff --git a/Source/items.cpp b/Source/items.cpp index 6fc2f5724..ea19ead0b 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -30,6 +30,7 @@ #include "options.h" #include "player.h" #include "stores.h" +#include "town.h" #include "utils/language.h" #include "utils/math.h" #include "utils/stdcompat/algorithm.hpp" @@ -4421,6 +4422,30 @@ void UseItem(int p, item_misc_id mid, spell_id spl) } } +bool UseItemOpensHive(const Item &item, Point position) +{ + if (item.IDidx != IDI_RUNEBOMB) + return false; + for (auto dir : PathDirs) { + Point adjacentPosition = position + dir; + if (OpensHive(adjacentPosition)) + return true; + } + return false; +} + +bool UseItemOpensCrypt(const Item &item, Point position) +{ + if (item.IDidx != IDI_MAPOFDOOM) + return false; + for (auto dir : PathDirs) { + Point adjacentPosition = position + dir; + if (OpensGrave(adjacentPosition)) + return true; + } + return false; +} + void SpawnSmith(int lvl) { constexpr int PinnedItemCount = 0; diff --git a/Source/items.h b/Source/items.h index 45f490a4e..390c66c9c 100644 --- a/Source/items.h +++ b/Source/items.h @@ -473,6 +473,8 @@ void DrawUniqueInfo(const Surface &out); void PrintItemDetails(Item *x); void PrintItemDur(Item *x); void UseItem(int p, item_misc_id Mid, spell_id spl); +bool UseItemOpensHive(const Item &item, Point position); +bool UseItemOpensCrypt(const Item &item, Point position); void SpawnSmith(int lvl); void SpawnPremium(int pnum); void SpawnWitch(int lvl);