From e6182709d19765b4e25cf2329f5a8ecf2068bd3c Mon Sep 17 00:00:00 2001 From: staphen Date: Sun, 3 Apr 2022 15:10:27 -0400 Subject: [PATCH] Allow casting Town Portal, Teleport, and Guardian scrolls from inventory --- Source/controls/plrctrls.cpp | 35 ++++++++++++++++++++++++----------- Source/items.cpp | 17 ++++------------- Source/spells.cpp | 10 ++++++++++ Source/spells.h | 1 + 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/Source/controls/plrctrls.cpp b/Source/controls/plrctrls.cpp index 377934020..c5722ae3f 100644 --- a/Source/controls/plrctrls.cpp +++ b/Source/controls/plrctrls.cpp @@ -1768,7 +1768,7 @@ bool SpellHasActorTarget() return pcursplr != -1 || pcursmonst != -1; } -void UpdateSpellTarget() +void UpdateSpellTarget(spell_id spell) { if (SpellHasActorTarget()) return; @@ -1778,7 +1778,7 @@ void UpdateSpellTarget() auto &myPlayer = Players[MyPlayerId]; - int range = myPlayer._pRSpell == SPL_TELEPORT ? 4 : 1; + int range = spell == SPL_TELEPORT ? 4 : 1; cursPosition = myPlayer.position.future + Displacement(myPlayer._pdir) * range; } @@ -1861,39 +1861,52 @@ void PerformSpellAction() return; } - UpdateSpellTarget(); + UpdateSpellTarget(myPlayer._pRSpell); CheckPlrSpell(false); } void CtrlUseInvItem() { - if (pcursinvitem == -1) + if (pcursinvitem == -1) { return; + } auto &myPlayer = Players[MyPlayerId]; - Item &item = GetInventoryItem(myPlayer, pcursinvitem); - if (item.IsScroll() && spelldata[item._iSpell].sTargeted) { - return; + if (item.IsScroll()) { + if (TargetsMonster(item._iSpell)) { + return; + } + if (spelldata[item._iSpell].sTargeted) { + UpdateSpellTarget(item._iSpell); + } } + int itemId = GetItemIdOnSlot(Slot); if (item.isEquipment()) { CheckInvItem(true, false); // auto-equip if it's an equipment } else { UseInvItem(MyPlayerId, pcursinvitem); } - if (itemId != GetItemIdOnSlot(Slot)) + if (itemId != GetItemIdOnSlot(Slot)) { ResetInvCursorPosition(); + } } void CtrlUseStashItem() { - if (pcursstashitem == uint16_t(-1)) + if (pcursstashitem == uint16_t(-1)) { return; + } const Item &item = Stash.stashList[pcursstashitem]; - if (item.IsScroll() && spelldata[item._iSpell].sTargeted) { - return; + if (item.IsScroll()) { + if (TargetsMonster(item._iSpell)) { + return; + } + if (spelldata[item._iSpell].sTargeted) { + UpdateSpellTarget(item._iSpell); + } } if (item.isEquipment()) { diff --git a/Source/items.cpp b/Source/items.cpp index 62e7f6e0c..cd3580aed 100644 --- a/Source/items.cpp +++ b/Source/items.cpp @@ -1810,10 +1810,7 @@ void PrintItemMisc(const Item &item) if (ControlMode == ControlTypes::KeyboardAndMouse) { AddPanelString(_("Right-click to read")); } else { - if (item.IsScrollOf(SPL_TELEPORT) || item.IsScrollOf(SPL_TOWN)) { - AddPanelString(_("Select from spell book, then")); - AddPanelString(_("cast spell to read")); - } else if (!invflag) { + if (!invflag) { AddPanelString(_("Open inventory to use")); } else { AddPanelString(_("Activate to read")); @@ -1825,13 +1822,7 @@ void PrintItemMisc(const Item &item) AddPanelString(_("Right-click to read, then")); AddPanelString(_("left-click to target")); } else { - if (item.IsScrollOf(SPL_FIREBALL) - || item.IsScrollOf(SPL_FIREWALL) - || item.IsScrollOf(SPL_FLAME) - || item.IsScrollOf(SPL_GUARDIAN) - || item.IsScrollOf(SPL_LIGHTNING) - || item.IsScrollOf(SPL_STONE) - || item.IsScrollOf(SPL_WAVE)) { + if (TargetsMonster(item._iSpell)) { AddPanelString(_("Select from spell book, then")); AddPanelString(_("cast spell to read")); } else if (!invflag) { @@ -3932,7 +3923,7 @@ void UseItem(int pnum, item_misc_id mid, spell_id spl) } break; case IMISC_SCROLL: - if (spelldata[spl].sTargeted) { + if (ControlMode == ControlTypes::KeyboardAndMouse && spelldata[spl].sTargeted) { player._pTSpell = spl; if (pnum == MyPlayerId) NewCursor(CURSOR_TELEPORT); @@ -3949,7 +3940,7 @@ void UseItem(int pnum, item_misc_id mid, spell_id spl) } break; case IMISC_SCROLLT: - if (spelldata[spl].sTargeted) { + if (ControlMode == ControlTypes::KeyboardAndMouse && spelldata[spl].sTargeted) { player._pTSpell = spl; if (pnum == MyPlayerId) NewCursor(CURSOR_TELEPORT); diff --git a/Source/spells.cpp b/Source/spells.cpp index 01a3dfb9e..65639475a 100644 --- a/Source/spells.cpp +++ b/Source/spells.cpp @@ -113,6 +113,16 @@ bool IsWallSpell(spell_id spl) return spl == SPL_FIREWALL || spl == SPL_LIGHTWALL; } +bool TargetsMonster(spell_id id) +{ + return id == SPL_FIREBALL + || id == SPL_FIREWALL + || id == SPL_FLAME + || id == SPL_LIGHTNING + || id == SPL_STONE + || id == SPL_WAVE; +} + int GetManaAmount(Player &player, spell_id sn) { int ma; // mana amount diff --git a/Source/spells.h b/Source/spells.h index 53806297c..821f4bde2 100644 --- a/Source/spells.h +++ b/Source/spells.h @@ -17,6 +17,7 @@ enum class SpellCheckResult : uint8_t { }; bool IsWallSpell(spell_id spl); +bool TargetsMonster(spell_id id); int GetManaAmount(Player &player, spell_id sn); void UseMana(int id, spell_id sn); SpellCheckResult CheckSpell(int id, spell_id sn, spell_type st, bool manaonly);