Browse Source

[controller] Correctly prioritize monsters

pull/508/head
Anders Jenbo 6 years ago
parent
commit
28b4fb1fd9
  1. 40
      SourceX/controls/plrctrls.cpp

40
SourceX/controls/plrctrls.cpp

@ -187,30 +187,29 @@ bool CanTargetMonster(int mi)
void FindRangedTarget() void FindRangedTarget()
{ {
int newRotations, newDdistance; int distance, rotations;
int distance = 2 * (MAXDUNX + MAXDUNY); bool currentCanTalk;
int rotations = 5;
// The first MAX_PLRS monsters are reserved for players' golems. // The first MAX_PLRS monsters are reserved for players' golems.
for (int i = MAX_PLRS; i < MAXMONSTERS; i++) { for (int mi = MAX_PLRS; mi < MAXMONSTERS; mi++) {
const auto &monst = monster[i]; const auto &monst = monster[mi];
const int mx = monst._mx; const int mx = monst._mx;
const int my = monst._my; const int my = monst._my;
if (!CanTargetMonster(i)) if (!CanTargetMonster(mi))
continue; continue;
newDdistance = GetDistanceRanged(mx, my); const int newDdistance = GetDistanceRanged(mx, my);
if (distance < newDdistance || (pcursmonst != -1 && CanTalkToMonst(i))) { if (pcursmonst != -1 && !currentCanTalk && distance < newDdistance) {
continue; continue;
} }
if (distance == newDdistance) { const int newRotations = GetRotaryDistance(mx, my);
newRotations = GetRotaryDistance(mx, my); if (pcursmonst != -1 && !currentCanTalk && distance == newDdistance && rotations < newRotations) {
if (rotations < newRotations) continue;
continue;
} }
distance = newDdistance; distance = newDdistance;
rotations = newRotations; rotations = newRotations;
pcursmonst = i; pcursmonst = mi;
currentCanTalk = CanTalkToMonst(mi);
} }
} }
@ -218,7 +217,8 @@ void FindMeleeTarget()
{ {
bool visited[MAXDUNX][MAXDUNY] = { 0 }; bool visited[MAXDUNX][MAXDUNY] = { 0 };
int maxSteps = 25; // Max steps for FindPath is 25 int maxSteps = 25; // Max steps for FindPath is 25
int rotations = 5; int rotations;
bool currentCanTalk;
struct SearchNode { struct SearchNode {
int x, y; int x, y;
@ -244,7 +244,7 @@ void FindMeleeTarget()
if (visited[dx][dy]) if (visited[dx][dy])
continue; // already visisted continue; // already visisted
if (node.steps >= maxSteps) { if (node.steps > maxSteps) {
visited[dx][dy] = true; visited[dx][dy] = true;
continue; continue;
} }
@ -256,11 +256,13 @@ void FindMeleeTarget()
const int mi = dMonster[dx][dy] > 0 ? dMonster[dx][dy] - 1 : -(dMonster[dx][dy] + 1); const int mi = dMonster[dx][dy] > 0 ? dMonster[dx][dy] - 1 : -(dMonster[dx][dy] + 1);
if (CanTargetMonster(mi)) { if (CanTargetMonster(mi)) {
const int newRotations = GetRotaryDistance(dx, dy); const int newRotations = GetRotaryDistance(dx, dy);
if (rotations < newRotations || (pcursmonst != -1 && CanTalkToMonst(i))) if (pcursmonst != -1 && !currentCanTalk && rotations < newRotations)
continue; continue;
rotations = newRotations; rotations = newRotations;
pcursmonst = mi; pcursmonst = mi;
maxSteps = node.steps; // Monsters found, cap search to current steps currentCanTalk = CanTalkToMonst(mi);
if (!currentCanTalk)
maxSteps = node.steps; // Monsters found, cap search to current steps
} }
} }
@ -377,7 +379,7 @@ void FindTrigger()
} }
} }
if (pcursmonst != -1 || pcursplr != -1) if (pcursmonst != -1 || pcursplr != -1 || cursmx == -1 || cursmy == -1)
return; // Prefer monster/player info text return; // Prefer monster/player info text
CheckTrigForce(); CheckTrigForce();
@ -813,6 +815,8 @@ void plrctrls_after_check_curs_move()
pcursobj = -1; pcursobj = -1;
pcursmissile = -1; pcursmissile = -1;
pcurstrig = -1; pcurstrig = -1;
cursmx = -1;
cursmy = -1;
if (!invflag) { if (!invflag) {
*infostr = '\0'; *infostr = '\0';
ClearPanel(); ClearPanel();

Loading…
Cancel
Save