summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/being/localplayer.cpp60
-rw-r--r--src/being/localplayer.h6
-rw-r--r--src/gui/widgets/avatarlistbox.cpp2
-rw-r--r--src/gui/widgets/tabs/socialnavigationtab.h2
-rw-r--r--src/gui/windows/minimap.cpp8
-rw-r--r--src/progs/manaplus/actions/commands.cpp11
-rw-r--r--src/progs/manaplus/gui/viewport.cpp24
7 files changed, 54 insertions, 59 deletions
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp
index 83b4816ae..1e2f16bea 100644
--- a/src/being/localplayer.cpp
+++ b/src/being/localplayer.cpp
@@ -137,8 +137,7 @@ LocalPlayer::LocalPlayer(const BeingId id,
mPingTime(0),
mAfkTime(0),
mActivityTime(0),
- mNavigateX(0),
- mNavigateY(0),
+ mNavigateDest(0, 0),
mNavigateId(BeingId_zero),
mCrossX(0),
mCrossY(0),
@@ -282,7 +281,7 @@ void LocalPlayer::logic()
if (!mSyncPlayerMove)
dist = 20;
- if (((mNavigateX != 0) || (mNavigateY != 0)) &&
+ if (((mNavigateDest.x != 0) || (mNavigateDest.y != 0)) &&
((mCrossX + dist >= mX && mCrossX <= mX + dist
&& mCrossY + dist >= mY && mCrossY <= mY + dist)
|| ((mCrossX == 0) && (mCrossY == 0))))
@@ -549,13 +548,13 @@ bool LocalPlayer::pickUp(FloorItem *const item)
break;
case 1:// should never happen due to above check for adjecent-tile
// pickup, but you never know.
- navigateTo(item->getTileX(), item->getTileY());
+ navigateTo({item->getTileX(), item->getTileY()});
break;
default:
{
// at least two spots, move nearby.
const Position& nearby = *(++debugPath.rbegin());
- navigateTo(nearby.x, nearby.y);
+ navigateTo(nearby);
break;
}
}
@@ -1059,8 +1058,7 @@ void LocalPlayer::setGotoTarget(Being *const target)
mPickUpTarget = nullptr;
setTarget(target);
mGoingToTarget = true;
- navigateTo(target->mX,
- target->mY);
+ navigateTo({target->mX, target->mY});
}
void LocalPlayer::handleStatusEffect(const StatusEffect *const effect,
@@ -1408,7 +1406,7 @@ void LocalPlayer::moveToTarget(int dist)
limit = CAST_S32(sz) - dist;
gotPos = true;
}
- else if ((mNavigateX != 0) || (mNavigateY != 0))
+ else if ((mNavigateDest.x != 0) || (mNavigateDest.y != 0))
{
debugPath = mNavigatePath;
limit = dist;
@@ -1420,7 +1418,7 @@ void LocalPlayer::moveToTarget(int dist)
if (dist == 0)
{
if (mTarget != nullptr)
- navigateTo(mTarget->mX, mTarget->mY);
+ navigateTo({mTarget->mX, mTarget->mY});
}
else
{
@@ -1433,12 +1431,12 @@ void LocalPlayer::moveToTarget(int dist)
{
pos = (*i);
}
- navigateTo(pos.x, pos.y);
+ navigateTo(pos);
}
}
else if ((mLastTargetX != 0) || (mLastTargetY != 0))
{
- navigateTo(mLastTargetX, mLastTargetY);
+ navigateTo({mLastTargetX, mLastTargetY});
}
}
@@ -1466,7 +1464,7 @@ void LocalPlayer::moveToHome()
}
else
{
- navigateTo(CAST_S32(pos.x), CAST_S32(pos.y));
+ navigateTo({CAST_S32(pos.x), CAST_S32(pos.y)});
}
}
}
@@ -1710,8 +1708,11 @@ void LocalPlayer::moveByDirection(const unsigned char dir)
void LocalPlayer::specialMove(const unsigned char direction)
{
- if ((direction != 0U) && ((mNavigateX != 0) || (mNavigateY != 0)))
+ if ((direction != 0U)
+ && ((mNavigateDest.x != 0) || (mNavigateDest.y != 0)))
+ {
navigateClean();
+ }
if ((direction != 0U) && (settings.moveType >= 2
&& settings.moveType <= 4))
@@ -2113,7 +2114,8 @@ void LocalPlayer::afkRespond(ChatTab *const tab, const std::string &nick)
}
}
-bool LocalPlayer::navigateTo(const int x, const int y)
+
+bool LocalPlayer::navigateTo(const Position& to)
{
if (mMap == nullptr)
return false;
@@ -2127,15 +2129,14 @@ bool LocalPlayer::navigateTo(const int x, const int y)
mOldY = mPixelY;
mOldTileX = mX;
mOldTileY = mY;
- mNavigateX = x;
- mNavigateY = y;
+ mNavigateDest = to;
mNavigateId = BeingId_zero;
mNavigatePath = mMap->findPath(
(mPixelX - mapTileSize / 2) / mapTileSize,
(mPixelY - mapTileSize) / mapTileSize,
- x,
- y,
+ to.x,
+ to.y,
getBlockWalkMask(),
0);
@@ -2144,6 +2145,7 @@ bool LocalPlayer::navigateTo(const int x, const int y)
return !mNavigatePath.empty();
}
+
void LocalPlayer::navigateClean()
{
if (mMap == nullptr)
@@ -2154,8 +2156,7 @@ void LocalPlayer::navigateClean()
mOldY = 0;
mOldTileX = 0;
mOldTileY = 0;
- mNavigateX = 0;
- mNavigateY = 0;
+ mNavigateDest = {0, 0};
mNavigateId = BeingId_zero;
mNavigatePath.clear();
@@ -2223,11 +2224,10 @@ void LocalPlayer::updateCoords()
navigateClean();
return;
}
- mNavigateX = being->mX;
- mNavigateY = being->mY;
+ mNavigateDest = {being->mX, being->mY};
}
- if (mNavigateX == x && mNavigateY == y)
+ if (mNavigateDest.x == x && mNavigateDest.y == y)
{
navigateClean();
return;
@@ -2529,7 +2529,7 @@ void LocalPlayer::followMoveTo(const Being *const being,
being->mName == mPlayerFollowed)
{
mPickUpTarget = nullptr;
- navigateTo(x, y);
+ navigateTo({x, y});
}
}
@@ -2547,20 +2547,20 @@ void LocalPlayer::followMoveTo(const Being *const being,
switch (settings.followMode)
{
case 0:
- navigateTo(x1, y1);
+ navigateTo({x1, y1});
setNextDest(x2, y2);
break;
case 1:
if (x1 != x2 || y1 != y2)
{
- navigateTo(mX + x2 - x1, mY + y2 - y1);
+ navigateTo({mX + x2 - x1, mY + y2 - y1});
setNextDest(mX + x2 - x1, mY + y2 - y1);
}
break;
case 2:
if (x1 != x2 || y1 != y2)
{
- navigateTo(mX + x1 - x2, mY + y1 - y2);
+ navigateTo({mX + x1 - x2, mY + y1 - y2});
setNextDest(mX + x1 - x2, mY + y1 - y2);
}
break;
@@ -2638,13 +2638,13 @@ void LocalPlayer::fixPos()
#endif
setTileCoords(mCrossX, mCrossY);
/*
- if (mNavigateX != 0 || mNavigateY != 0)
+ if (mNavigateDest.x != 0 || mNavigateDest.y != 0)
{
#ifdef ENABLEDEBUGLOG
logger->dlog(strprintf("Renavigate to (%d,%d)",
- mNavigateX, mNavigateY));
+ mNavigateDest.x, mNavigateDest.y));
#endif
- navigateTo(mNavigateX, mNavigateY);
+ navigateTo({mNavigateDest.x, mNavigateDest.y});
}
*/
// alternative way to fix, move to real position
diff --git a/src/being/localplayer.h b/src/being/localplayer.h
index 1770bd4d3..a972e9d6e 100644
--- a/src/being/localplayer.h
+++ b/src/being/localplayer.h
@@ -243,10 +243,11 @@ class LocalPlayer final : public Being,
static void setAfkMessage(std::string message);
- bool navigateTo(const int x, const int y);
+ bool navigateTo(const Position& to);
void navigateClean();
+
void imitateEmote(const Being *const being,
const unsigned char action) const;
@@ -486,8 +487,7 @@ class LocalPlayer final : public Being,
time_t mPingTime;
time_t mAfkTime;
time_t mActivityTime;
- int mNavigateX;
- int mNavigateY;
+ Position mNavigateDest;
BeingId mNavigateId;
int mCrossX;
int mCrossY;
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp
index 66c1b12c1..6c18643ba 100644
--- a/src/gui/widgets/avatarlistbox.cpp
+++ b/src/gui/widgets/avatarlistbox.cpp
@@ -629,7 +629,7 @@ void AvatarListBox::mousePressed(MouseEvent &event)
else
#endif // TMWA_SUPPORT
{
- localPlayer->navigateTo(ava->getX(), ava->getY());
+ localPlayer->navigateTo({ava->getX(), ava->getY()});
}
}
else if (eventButton == MouseButton::RIGHT)
diff --git a/src/gui/widgets/tabs/socialnavigationtab.h b/src/gui/widgets/tabs/socialnavigationtab.h
index dc11060c0..4b69d0bbb 100644
--- a/src/gui/widgets/tabs/socialnavigationtab.h
+++ b/src/gui/widgets/tabs/socialnavigationtab.h
@@ -177,7 +177,7 @@ class SocialNavigationTab final : public SocialTab
const Avatar *const ava = avatars->at(num);
if (ava != nullptr)
- localPlayer->navigateTo(ava->getX(), ava->getY());
+ localPlayer->navigateTo({ava->getX(), ava->getY()});
}
void updateNames()
diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp
index d40efd032..ae1c0038e 100644
--- a/src/gui/windows/minimap.cpp
+++ b/src/gui/windows/minimap.cpp
@@ -495,11 +495,9 @@ void Minimap::mouseReleased(MouseEvent &event)
if (event.getButton() == MouseButton::LEFT)
{
- int x = event.getX();
- int y = event.getY();
- screenToMap(x, y);
-
- localPlayer->navigateTo(x, y);
+ Position pos(event.getX(), event.getY());
+ screenToMap(pos.x, pos.y);
+ localPlayer->navigateTo(pos);
}
else if (event.getButton() == MouseButton::RIGHT)
{
diff --git a/src/progs/manaplus/actions/commands.cpp b/src/progs/manaplus/actions/commands.cpp
index 53c0996ac..443217de2 100644
--- a/src/progs/manaplus/actions/commands.cpp
+++ b/src/progs/manaplus/actions/commands.cpp
@@ -483,11 +483,10 @@ impHandler(navigate)
return false;
}
- int x = 0;
- int y = 0;
+ Position dest {0, 0};
- if (parse2Int(event.args, x, y))
- localPlayer->navigateTo(x, y);
+ if (parse2Int(event.args, dest.x, dest.y))
+ localPlayer->navigateTo(dest);
else
localPlayer->navigateClean();
return true;
@@ -509,7 +508,7 @@ impHandler(navigateTo)
ActorType::Unknown);
if (being != nullptr)
{
- localPlayer->navigateTo(being->getTileX(), being->getTileY());
+ localPlayer->navigateTo({being->getTileX(), being->getTileY()});
}
else if (localPlayer->isInParty())
{
@@ -523,7 +522,7 @@ impHandler(navigateTo)
o != nullptr &&
m->getMap() == o->getMap())
{
- localPlayer->navigateTo(m->getX(), m->getY());
+ localPlayer->navigateTo({m->getX(), m->getY()});
}
}
}
diff --git a/src/progs/manaplus/gui/viewport.cpp b/src/progs/manaplus/gui/viewport.cpp
index 5483b3d0e..a091a2c75 100644
--- a/src/progs/manaplus/gui/viewport.cpp
+++ b/src/progs/manaplus/gui/viewport.cpp
@@ -724,7 +724,7 @@ void Viewport::walkByMouse(const MouseEvent &event)
BlockMask::WATER |
BlockMask::PLAYERWALL))
{
- localPlayer->navigateTo(playerX + dx, playerY + dy);
+ localPlayer->navigateTo({playerX + dx, playerY + dy});
}
else
{
@@ -810,29 +810,27 @@ void Viewport::walkByMouse(const MouseEvent &event)
}
}
}
- localPlayer->navigateTo(playerX + dx, playerY + dy);
+ localPlayer->navigateTo({playerX + dx, playerY + dy});
}
}
else
{
- int destX;
- int destY;
- getMouseTile(event.getX(), event.getY(),
- destX, destY);
- if (playerX != destX || playerY != destY)
+ Position dest {0, 0};
+ getMouseTile(event.getX(), event.getY(), dest.x, dest.y);
+ if (playerX != dest.x || playerY != dest.y)
{
- if (!localPlayer->navigateTo(destX, destY))
+ if (!localPlayer->navigateTo(dest))
{
- if (playerX > destX)
+ if (playerX > dest.x)
playerX --;
- else if (playerX < destX)
+ else if (playerX < dest.x)
playerX ++;
- if (playerY > destY)
+ if (playerY > dest.y)
playerY --;
- else if (playerY < destY)
+ else if (playerY < dest.y)
playerY ++;
if (mMap->getWalk(playerX, playerY, 0))
- localPlayer->navigateTo(playerX, playerY);
+ localPlayer->navigateTo({playerX, playerY});
}
}
}