From ee23f41e0c59ec8da6f3734536406da8b956ae78 Mon Sep 17 00:00:00 2001 From: staphen Date: Mon, 11 Oct 2021 18:44:08 -0400 Subject: [PATCH] Enable opening Hive and Crypt using gamepad --- Source/controls/plrctrls.cpp | 23 +++++++++++++++++++++++ Source/inv.cpp | 29 ++++++++++++++++------------- Source/town.cpp | 14 ++++++++++++++ Source/town.h | 14 ++++++++++++++ 4 files changed, 67 insertions(+), 13 deletions(-) diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index b8b1b997b..b05b18bbc 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -18,6 +18,7 @@ #include "minitext.h" #include "missiles.h" #include "stores.h" +#include "town.h" #include "towners.h" #include "trigs.h" @@ -1398,6 +1399,28 @@ 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 (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; + } + } + } + cursPosition = myPlayer.position.future + Direction::SouthEast; if (!DropItemBeforeTrig()) { // Try to drop on the other side diff --git a/Source/inv.cpp b/Source/inv.cpp index c5e1103f4..35cc42ce1 100644 --- a/Source/inv.cpp +++ b/Source/inv.cpp @@ -20,6 +20,7 @@ #include "options.h" #include "plrmsg.h" #include "stores.h" +#include "town.h" #include "towners.h" #include "controls/plrctrls.h" #include "utils/language.h" @@ -1722,33 +1723,28 @@ bool TryInvPut() int InvPutItem(Player &player, Point position) { - if (!PutItem(player, position)) - return -1; - - if (currlevel == 0) { - int yp = cursPosition.y; - int xp = cursPosition.x; - if (player.HoldItem._iCurs == ICURS_RUNE_BOMB && xp >= 79 && xp <= 82 && yp >= 61 && yp <= 64) { + 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) { + if (gbIsMultiplayer) NetSendCmdQuest(true, quest); - return -1; - } return -1; } - if (player.HoldItem.IDidx == IDI_MAPOFDOOM && xp >= 35 && xp <= 38 && yp >= 20 && yp <= 24) { + if (player.HoldItem.IDidx == IDI_MAPOFDOOM && OpensGrave(position)) { NetSendCmd(false, CMD_OPENCRYPT); auto &quest = Quests[Q_GRAVE]; quest._qactive = QUEST_DONE; - if (gbIsMultiplayer) { + if (gbIsMultiplayer) NetSendCmdQuest(true, quest); - } return -1; } } + if (!PutItem(player, position)) + return -1; + assert(CanPut(position)); int ii = AllocateItem(); @@ -1771,6 +1767,13 @@ int InvPutItem(Player &player, Point position) int SyncPutItem(Player &player, Point position, int idx, uint16_t icreateinfo, int iseed, int id, int dur, int mdur, int ch, int mch, int ivalue, uint32_t ibuff, int toHit, int maxDam, int minStr, int minMag, int minDex, int ac) { + if (player.plrlevel == 0) { + if (idx == IDI_RUNEBOMB && OpensHive(position)) + return -1; + if (idx == IDI_MAPOFDOOM && OpensGrave(position)) + return -1; + } + if (!PutItem(player, position)) return -1; diff --git a/Source/town.cpp b/Source/town.cpp index f9687eafc..2edce856d 100644 --- a/Source/town.cpp +++ b/Source/town.cpp @@ -200,6 +200,20 @@ void DrlgTPass3() } // namespace +bool OpensHive(Point position) +{ + int yp = position.y; + int xp = position.x; + return xp >= 79 && xp <= 82 && yp >= 61 && yp <= 64; +} + +bool OpensGrave(Point position) +{ + int yp = position.y; + int xp = position.x; + return xp >= 35 && xp <= 38 && yp >= 20 && yp <= 24; +} + void TownOpenHive() { dPiece[78][60] = 0x48a; diff --git a/Source/town.h b/Source/town.h index d548d3c07..688e91a2d 100644 --- a/Source/town.h +++ b/Source/town.h @@ -10,6 +10,20 @@ namespace devilution { +/** + * @brief Check if hive can be opened by dropping rune bomb on a tile + * @param position The position of the tile + * @return True if the bomb would open hive +*/ +bool OpensHive(Point position); + +/** + * @brief Check if grave can be opened by dropping cathedral map on a tile + * @param position The position of the tile + * @return True if the map would open the grave +*/ +bool OpensGrave(Point position); + /** * @brief Update the map to show the open hive */