summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--src/gui/viewport.cpp16
-rw-r--r--src/localplayer.cpp18
-rw-r--r--src/localplayer.h11
-rw-r--r--src/main.h3
5 files changed, 38 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 7777e3fc..36d175a3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,13 +6,16 @@
src/net/chatserver/party.h, src/localplayer.h: Added basic party
support.
-
2008-04-17 Yohann Ferreira <bertram@cegetel.net>
* src/gui/progressbar.h, src/gui/progressbar.cpp: Added smooth
changes in progressbar.
* src/net/chatserver/chatserver.h: One file was forgotten into the
private channels removal.
+ * src/localplayer.h, src/localplayer.cpp, src/gui/viewport.cpp,
+ src/main.h: Added input type parameter to the
+ LocalPlayer::SetDestination methods in order to keep control over
+ message flooding to the server with mouse dragging.
2008-04-16 David Athay <ko2fan@gmail.com>
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 33449659..1b6cfa1c 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -253,9 +253,10 @@ Viewport::logic()
if (mPlayerFollowMouse && button & SDL_BUTTON(1) &&
mWalkTime != player_node->mWalkTime)
{
- player_node->setDestination(mouseX + (int) mViewX,
- mouseY + (int) mViewY);
- mWalkTime = player_node->mWalkTime;
+ player_node->setDestination(mouseX + (int) mViewX,
+ mouseY + (int) mViewY,
+ BY_MOUSE);
+ mWalkTime = player_node->mWalkTime;
}
for (int i = Being::TC_SMALL; i < Being::NUM_TC; i++)
@@ -396,12 +397,14 @@ Viewport::mousePressed(gcn::MouseEvent &event)
// Just walk around
else
{
- // XXX XXX XXX REALLY UGLY!
+ // FIXME: REALLY UGLY!
Uint8 *keys = SDL_GetKeyState(NULL);
if (!(keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT]))
{
+
player_node->setDestination(event.getX() + (int) mViewX,
- event.getY() + (int) mViewY);
+ event.getY() + (int) mViewY,
+ BY_MOUSE);
}
mPlayerFollowMouse = true;
}
@@ -429,7 +432,8 @@ Viewport::mouseDragged(gcn::MouseEvent &event)
if (mPlayerFollowMouse && mWalkTime == player_node->mWalkTime)
{
player_node->setDestination(event.getX() + (int) mViewX,
- event.getY() + (int) mViewY);
+ event.getY() + (int) mViewY,
+ BY_MOUSE);
}
}
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 78dac6f8..e4c2624e 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -66,6 +66,7 @@ LocalPlayer::LocalPlayer():
mTrading(false),
mLastAction(-1), mWalkingDir(0),
mDestX(0), mDestY(0),
+ mLocalWalkTime(-1),
mExpMessageTime(0)
{
}
@@ -222,7 +223,8 @@ void LocalPlayer::pickUp(FloorItem *item)
Net::GameServer::Player::pickUp(id >> 16, id & 0xFFFF);
mPickUpTarget = NULL;
} else {
- setDestination(item->getX() * 32 + 16, item->getY() * 32 + 16);
+ setDestination(item->getX() * 32 + 16, item->getY() * 32 + 16,
+ BY_SYSTEM);
mPickUpTarget = item;
}
}
@@ -262,7 +264,7 @@ void LocalPlayer::walk(unsigned char dir)
// Walk to where the player can actually go
if ((dx || dy) && mMap->getWalk((mX + dx) / 32, (mY + dy) / 32, getWalkMask()))
{
- setDestination(mX + dx, mY + dy);
+ setDestination(mX + dx, mY + dy, BY_SYSTEM);
}
else if (dir)
{
@@ -272,7 +274,7 @@ void LocalPlayer::walk(unsigned char dir)
}
}
-void LocalPlayer::setDestination(Uint16 x, Uint16 y)
+void LocalPlayer::setDestination(Uint16 x, Uint16 y, InputType inputType)
{
// Fix coordinates so that the player does not seem to dig into walls.
int tx = x / 32, ty = y / 32, fx = x % 32, fy = y % 32;
@@ -285,6 +287,14 @@ void LocalPlayer::setDestination(Uint16 x, Uint16 y)
// Only send a new message to the server when destination changes
if (x != mDestX || y != mDestY)
{
+ // Using mouse, Walkings are allowed twice per second
+ if (inputType == BY_MOUSE && get_elapsed_time(mLocalWalkTime) < 500) return;
+
+ // Using keyboard, Walkings are allowed ten times per second
+ if (inputType == BY_KEYBOARD && get_elapsed_time(mLocalWalkTime) < 100) return;
+
+ mLocalWalkTime = tick_time;
+
mDestX = x;
mDestY = y;
@@ -292,8 +302,8 @@ void LocalPlayer::setDestination(Uint16 x, Uint16 y)
particleEngine->addEffect("graphics/particles/hit.particle.xml", x, y);
}
- mPickUpTarget = NULL;
Being::setDestination(x, y);
+ mPickUpTarget = NULL;
}
void LocalPlayer::setWalkingDir(int dir)
diff --git a/src/localplayer.h b/src/localplayer.h
index b5e7c3eb..2813ca77 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -28,9 +28,6 @@
#include <memory>
-// TODO move into some sane place...
-#define MAX_SLOT 2
-
class FloorItem;
class Inventory;
class Item;
@@ -118,6 +115,10 @@ enum
NB_CHARACTER_ATTRIBUTES = CHAR_SKILL_END
};
+enum InputType {
+ BY_MOUSE = 0, BY_KEYBOARD, BY_SYSTEM
+};
+
/**
* The local player character.
@@ -248,7 +249,7 @@ class LocalPlayer : public Player
/**
* Sets a new destination for this being to walk to.
*/
- void setDestination(Uint16 x, Uint16 y);
+ void setDestination(Uint16 x, Uint16 y, InputType inputType);
/**
* Sets a new direction to keep walking in.
@@ -371,6 +372,8 @@ class LocalPlayer : public Player
int mWalkingDir; /**< The direction the player is walking in. */
int mDestX; /**< X coordinate of destination. */
int mDestY; /**< Y coordinate of destination. */
+ int mLocalWalkTime; /**< Time in millisecs before the next walk
+ can be sent when using mouse. */
std::list<std::string> mExpMessages; /**< Queued exp messages*/
int mExpMessageTime;
diff --git a/src/main.h b/src/main.h
index 691660e5..3835f355 100644
--- a/src/main.h
+++ b/src/main.h
@@ -116,6 +116,9 @@ const short defaultMusicVolume = 60;
const std::string defaultAccountServerName = "testing.themanaworld.org";
const short defaultAccountServerPort = 9601;
+// Defines the number of usable player slots
+const short maxSlot = 2;
+
extern std::string token;
extern unsigned char state;
extern std::string errorMessage;