Browse Source

QuickCast fixes

pull/8140/head
wkdgmr 7 months ago
parent
commit
85dde89997
  1. 51
      Source/controls/plrctrls.cpp

51
Source/controls/plrctrls.cpp

@ -1,5 +1,3 @@
#include "controls/plrctrls.h"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <cstdint> #include <cstdint>
@ -17,6 +15,7 @@
#endif #endif
#include "controls/control_mode.hpp" #include "controls/control_mode.hpp"
#include "controls/game_controls.h" #include "controls/game_controls.h"
#include "controls/plrctrls.h"
#include "controls/touch/gamepad.h" #include "controls/touch/gamepad.h"
#include "cursor.h" #include "cursor.h"
#include "doom.h" #include "doom.h"
@ -411,10 +410,14 @@ void CheckPlayerNearby()
void FindActor() void FindActor()
{ {
if (leveltype != DTYPE_TOWN) if (leveltype != DTYPE_TOWN) {
CheckMonstersNearby(); CheckMonstersNearby();
else // Always prefer monsters for spell casting if a monster is targeted
if (pcursmonst != -1)
cursPosition = Monsters[pcursmonst].position.tile;
} else {
CheckTownersNearby(); CheckTownersNearby();
}
if (gbIsMultiplayer) if (gbIsMultiplayer)
CheckPlayerNearby(); CheckPlayerNearby();
@ -479,6 +482,13 @@ void FindTrigger()
CheckRportal(); CheckRportal();
} }
void PreferMonsterTarget()
{
if (ControlMode == ControlTypes::Gamepad && pcursmonst != -1 && (ObjectUnderCursor != nullptr || pcursitem != -1)) {
cursPosition = Monsters[pcursmonst].position.tile;
}
}
bool IsStandingGround() bool IsStandingGround()
{ {
if (ControlMode == ControlTypes::Gamepad) { if (ControlMode == ControlTypes::Gamepad) {
@ -1948,6 +1958,7 @@ void plrctrls_after_check_curs_move()
FindActor(); FindActor();
FindItemOrObject(); FindItemOrObject();
FindTrigger(); FindTrigger();
PreferMonsterTarget();
} }
} }
@ -2018,31 +2029,30 @@ void PerformPrimaryAction()
Interact(); Interact();
} }
bool SpellHasActorTarget() bool SpellHasActorTarget(SpellID spell)
{ {
const SpellID spl = MyPlayer->_pRSpell; if (spell == SpellID::TownPortal || spell == SpellID::Teleport)
if (spl == SpellID::TownPortal || spl == SpellID::Teleport)
return false; return false;
if (IsWallSpell(spl) && pcursmonst != -1) {
cursPosition = Monsters[pcursmonst].position.tile;
}
return PlayerUnderCursor != nullptr || pcursmonst != -1; return PlayerUnderCursor != nullptr || pcursmonst != -1;
} }
void UpdateSpellTarget(SpellID spell) void UpdateSpellTarget(SpellID spell)
{ {
if (SpellHasActorTarget()) // For wall spells, if a monster is targeted, always set cursPosition to the monster's tile
if (IsWallSpell(spell) && pcursmonst != -1) {
cursPosition = Monsters[pcursmonst].position.tile;
return;
}
if (SpellHasActorTarget(spell))
return; return;
PlayerUnderCursor = nullptr; PlayerUnderCursor = nullptr;
pcursmonst = -1; pcursmonst = -1;
const Player &myPlayer = *MyPlayer; const Player &myPlayer = *MyPlayer;
const int range = spell == SpellID::Teleport ? 4 : 1; const int range = spell == SpellID::Teleport ? 4 : 1;
cursPosition = myPlayer.position.future + Displacement(myPlayer._pdir) * range; cursPosition = myPlayer.position.future + Displacement(myPlayer._pdir) * range;
} }
@ -2236,10 +2246,15 @@ void PerformSecondaryAction()
NewCursor(CURSOR_HAND); NewCursor(CURSOR_HAND);
if (pcursitem != -1) { if (pcursitem != -1) {
NetSendCmdLocParam1(true, CMD_GOTOAGETITEM, cursPosition, pcursitem); // Use item's actual position for interaction
const Item &item = Items[pcursitem];
NetSendCmdLocParam1(true, CMD_GOTOAGETITEM, item.position, pcursitem);
return;
} else if (ObjectUnderCursor != nullptr) { } else if (ObjectUnderCursor != nullptr) {
NetSendCmdLoc(MyPlayerId, true, CMD_OPOBJXY, cursPosition); // Use object's actual position for interaction
NetSendCmdLoc(MyPlayerId, true, CMD_OPOBJXY, ObjectUnderCursor->position);
LastPlayerAction = PlayerActionType::OperateObject; LastPlayerAction = PlayerActionType::OperateObject;
return;
} else { } else {
if (pcursmissile != nullptr) { if (pcursmissile != nullptr) {
MakePlrPath(myPlayer, pcursmissile->position.tile, true); MakePlrPath(myPlayer, pcursmissile->position.tile, true);
@ -2261,8 +2276,8 @@ void QuickCast(size_t slot)
const SpellID spell = myPlayer._pSplHotKey[slot]; const SpellID spell = myPlayer._pSplHotKey[slot];
const SpellType spellType = myPlayer._pSplTHotKey[slot]; const SpellType spellType = myPlayer._pSplTHotKey[slot];
if (ControlMode != ControlTypes::KeyboardAndMouse) { if (!IsGamepadAimActive) {
UpdateSpellTarget(spell); UpdateSpellTarget(spell);
} }
CheckPlrSpell(false, spell, spellType); CheckPlrSpell(false, spell, spellType);

Loading…
Cancel
Save