Browse Source

Allow casting Town Portal, Teleport, and Guardian scrolls from inventory

pull/4019/head^2
staphen 4 years ago committed by Anders Jenbo
parent
commit
e6182709d1
  1. 35
      Source/controls/plrctrls.cpp
  2. 17
      Source/items.cpp
  3. 10
      Source/spells.cpp
  4. 1
      Source/spells.h

35
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()) {

17
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);

10
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

1
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);

Loading…
Cancel
Save