diff --git a/Source/cursor.cpp b/Source/cursor.cpp index 7889394c2..53e58bb7d 100644 --- a/Source/cursor.cpp +++ b/Source/cursor.cpp @@ -5,7 +5,7 @@ DEVILUTION_BEGIN_NAMESPACE int cursH; int icursH28; int cursW; -int pcursmonst; +int pcursmonst = -1; int icursW28; BYTE *pCursCels; int icursH; diff --git a/SourceX/controls/plrctrls.cpp b/SourceX/controls/plrctrls.cpp index 24efcb8b0..158d11a38 100644 --- a/SourceX/controls/plrctrls.cpp +++ b/SourceX/controls/plrctrls.cpp @@ -119,6 +119,8 @@ void FindItemOrObject() int newRotations = GetRotaryDistance(mx + xx, my + yy); if (rotations < newRotations) continue; + if (xx != 0 && yy != 0 && GetDistance(mx + xx, my + yy, 1) == 0) + continue; rotations = newRotations; pcursitem = i; cursmx = mx + xx; @@ -141,6 +143,8 @@ void FindItemOrObject() int newRotations = GetRotaryDistance(mx + xx, my + yy); if (rotations < newRotations) continue; + if (xx != 0 && yy != 0 && GetDistance(mx + xx, my + yy, 1) == 0) + continue; rotations = newRotations; pcursobj = o; cursmx = mx + xx; @@ -202,17 +206,21 @@ void FindRangedTarget() if (!CanTargetMonster(mi)) continue; - const int newDdistance = GetDistanceRanged(mx, my); - const int newCanTalk = CanTalkToMonst(mi); - if (pcursmonst != -1 && !canTalk && (newCanTalk || distance < newDdistance)) + const bool newCanTalk = CanTalkToMonst(mi); + if (pcursmonst != -1 && !canTalk && newCanTalk) continue; + const int newDdistance = GetDistanceRanged(mx, my); const int newRotations = GetRotaryDistance(mx, my); - if (pcursmonst != -1 && !canTalk && distance == newDdistance && rotations < newRotations) - continue; + if (pcursmonst != -1 && canTalk == newCanTalk) { + if (distance < newDdistance) + continue; + if (distance == newDdistance && rotations < newRotations) + continue; + } distance = newDdistance; rotations = newRotations; - pcursmonst = mi; canTalk = newCanTalk; + pcursmonst = mi; } } @@ -258,13 +266,15 @@ void FindMeleeTarget() if (dMonster[dx][dy] != 0) { const int mi = dMonster[dx][dy] > 0 ? dMonster[dx][dy] - 1 : -(dMonster[dx][dy] + 1); if (CanTargetMonster(mi)) { - const int newRotations = GetRotaryDistance(dx, dy); const bool newCanTalk = CanTalkToMonst(mi); - if (pcursmonst != -1 && !canTalk && (newCanTalk || rotations < newRotations)) + if (pcursmonst != -1 && !canTalk && newCanTalk) + continue; + const int newRotations = GetRotaryDistance(dx, dy); + if (pcursmonst != -1 && canTalk == newCanTalk && rotations < newRotations) continue; rotations = newRotations; - pcursmonst = mi; canTalk = newCanTalk; + pcursmonst = mi; if (!canTalk) maxSteps = node.steps; // Monsters found, cap search to current steps }