summaryrefslogtreecommitdiff
path: root/src/localplayer.cpp
diff options
context:
space:
mode:
authorBertram <bertram@cegetel.net>2009-10-09 03:43:13 +0200
committerBertram <bertram@cegetel.net>2009-10-09 03:43:13 +0200
commit0a3e2c75c5fcc359e257548267d5ffae6726e2db (patch)
treefde0bb90528bc10a12be7a0a9101befbb954f29e /src/localplayer.cpp
parent07c92a402d3455bb2785c1fc69d03263888793b9 (diff)
downloadmana-client-0a3e2c75c5fcc359e257548267d5ffae6726e2db.tar.gz
mana-client-0a3e2c75c5fcc359e257548267d5ffae6726e2db.tar.bz2
mana-client-0a3e2c75c5fcc359e257548267d5ffae6726e2db.tar.xz
mana-client-0a3e2c75c5fcc359e257548267d5ffae6726e2db.zip
Mostly fixed keyboard movement on TMWserv.
- Making sure that keyboard and mouse are fully working on eAthena. - Making sure the mouse code isn't broken again. There are some glitches left but it's coming! What's left to be fixed: - Come a little closer to walls (localPlyer::nextStep() improvement to be done). - Adapt the next Step range according to the being speed. (again in nextStep()). - Handle more nicely player's direction when walking diagonally. - Get player's speed from server. Enjoy :)
Diffstat (limited to 'src/localplayer.cpp')
-rw-r--r--src/localplayer.cpp125
1 files changed, 79 insertions, 46 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 2744f106..65f1fcc7 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -73,10 +73,10 @@
#include <cassert>
#ifdef TMWSERV_SUPPORT
-// This is shorter then it really needs to be for normal use
-// But if we ever wanted to increase player speed, having this lower
-// Won't hurt
-const short walkingKeyboardDelay = 40;
+// This is the minimal delay between to permitted
+// setDestination() calls using the keyboard.
+// TODO: This can fine tuned later on when running is added...
+const short walkingKeyboardDelay = 1000;
#endif
LocalPlayer *player_node = NULL;
@@ -263,9 +263,10 @@ void LocalPlayer::setGMLevel(int level)
setGM(true);
}
-#ifdef EATHENA_SUPPORT
-void LocalPlayer::nextStep()
+
+void LocalPlayer::nextStep(unsigned char dir = 0)
{
+#ifdef EATHENA_SUPPORT
// TODO: Fix picking up when reaching target (this method is obsolete)
// TODO: Fix holding walking button to keep walking smoothly
if (mPath.empty())
@@ -274,7 +275,7 @@ void LocalPlayer::nextStep()
pickUp(mPickUpTarget);
if (mWalkingDir)
- walk(mWalkingDir);
+ startWalking(mWalkingDir);
}
// TODO: Fix automatically walking within range of target, when wanted
@@ -294,8 +295,66 @@ void LocalPlayer::nextStep()
Player::nextStep();
-}
+#else // TMWSERV_SUPPORT
+ if (!mMap || !dir)
+ return;
+
+ const Vector &pos = getPosition();
+
+ // Compute where the next step will set.
+
+ int dx = 0, dy = 0;
+ if (dir & UP)
+ dy--;
+ if (dir & DOWN)
+ dy++;
+ if (dir & LEFT)
+ dx--;
+ if (dir & RIGHT)
+ dx++;
+
+ // Prevent skipping corners over colliding tiles
+ if (dx && !mMap->getWalk(((int) pos.x + dx) / 32,
+ (int) pos.y / 32, getWalkMask()))
+ dx = 16 - (int) pos.x % 32;
+ if (dy && !mMap->getWalk((int) pos.x / 32,
+ ((int) pos.y + dy) / 32, getWalkMask()))
+ dy = 16 - (int) pos.y % 32;
+
+ // Choose a straight direction when diagonal target is blocked
+ if (dx && dy && !mMap->getWalk((pos.x + dx) / 32,
+ (pos.y + dy) / 32, getWalkMask()))
+ dx = 16 - (int) pos.x % 32;
+
+ int dScaler; // Distance to walk
+
+ // Checks our path up to 1 tiles, if a blocking tile is found
+ // We go to the last good tile, and break out of the loop
+ for (dScaler = 1; dScaler <= 32; dScaler++)
+ {
+ if ( (dx || dy) &&
+ !mMap->getWalk( ((int) pos.x + (dx * dScaler)) / 32,
+ ((int) pos.y + (dy * dScaler)) / 32, getWalkMask()) )
+ {
+ dScaler--;
+ break;
+ }
+ }
+
+ if (dScaler >= 0)
+ {
+ //effectManager->trigger(15, (int) pos.x + (dx * dScaler), (int) pos.y + (dy * dScaler));
+ setDestination((int) pos.x + (dx * dScaler), (int) pos.y + (dy * dScaler));
+ }
+ else if (dir)
+ {
+ // If the being can't move, just change direction
+ Net::getPlayerHandler()->setDirection(dir);
+ setDirection(dir);
+ }
#endif
+}
+
#ifdef TMWSERV_SUPPORT
bool LocalPlayer::checkInviteRights(const std::string &guildName)
@@ -497,11 +556,17 @@ void LocalPlayer::setWalkingDir(int dir)
// If we're not already walking, start walking.
if (mAction != WALK && dir)
{
- walk(dir);
+ startWalking(dir);
+ }
+#ifdef TMWSERV_SUPPORT
+ else if (mAction == WALK)
+ {
+ nextStep(dir);
}
+#endif
}
-void LocalPlayer::walk(unsigned char dir)
+void LocalPlayer::startWalking(unsigned char dir)
{
// This function is called by setWalkingDir(),
// but also by nextStep() for eAthena...
@@ -535,48 +600,14 @@ void LocalPlayer::walk(unsigned char dir)
if (dir & RIGHT)
dx++;
+#ifdef EATHENA_SUPPORT
// Prevent skipping corners over colliding tiles
-#ifdef TMWSERV_SUPPORT
- if (dx && !mMap->getWalk(((int) pos.x + dx) / 32,
- (int) pos.y / 32, getWalkMask()))
- dx = 16 - (int) pos.x % 32;
- if (dy && !mMap->getWalk((int) pos.x / 32,
- ((int) pos.y + dy) / 32, getWalkMask()))
- dy = 16 - (int) pos.y % 32;
-#else
if (dx && !mMap->getWalk(getTileX() + dx, getTileY(), getWalkMask()))
dx = 0;
if (dy && !mMap->getWalk(getTileX(), getTileY() + dy, getWalkMask()))
dy = 0;
-#endif
// Choose a straight direction when diagonal target is blocked
-#ifdef TMWSERV_SUPPORT
- if (dx && dy && !mMap->getWalk((pos.x + dx) / 32,
- (pos.y + dy) / 32, getWalkMask()))
- dx = 16 - (int) pos.x % 32;
-
- int dScaler; // Distance to walk
-
- // Checks our path up to 2 tiles, if a blocking tile is found
- // We go to the last good tile, and break out of the loop
- for (dScaler = 1; dScaler <= 32 * 2; dScaler++)
- {
- if ( (dx || dy) &&
- !mMap->getWalk( ((int) pos.x + (dx * dScaler)) / 32,
- ((int) pos.y + (dy * dScaler)) / 32, getWalkMask()) )
- {
- dScaler--;
- break;
- }
- }
-
- if (dScaler >= 0)
- {
- effectManager->trigger(15, (int) pos.x + (dx * dScaler), (int) pos.y + (dy * dScaler));
- setDestination((int) pos.x + (dx * dScaler), (int) pos.y + (dy * dScaler));
- }
-#else
if (dx && dy && !mMap->getWalk(getTileX() + dx, getTileY() + dy, getWalkMask()))
dx = 0;
@@ -585,13 +616,15 @@ void LocalPlayer::walk(unsigned char dir)
{
setDestination(getTileX() + dx, getTileY() + dy);
}
-#endif
else if (dir)
{
// If the being can't move, just change direction
Net::getPlayerHandler()->setDirection(dir);
setDirection(dir);
}
+#else // TMWSERV_SUPPORT
+ nextStep(dir);
+#endif
}
void LocalPlayer::stopWalking(bool sendToServer)