summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2012-01-20 02:01:14 +0100
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2012-01-27 19:20:26 +0100
commit0432de0928fbd41d6519a39e2e7212df66910013 (patch)
tree626dacc78bf735e2c446e9153afa31a0559f5a77 /src
parent5e8cc46a21e03acc7589fca181f7fae677853b29 (diff)
downloadmana-0432de0928fbd41d6519a39e2e7212df66910013.tar.gz
mana-0432de0928fbd41d6519a39e2e7212df66910013.tar.bz2
mana-0432de0928fbd41d6519a39e2e7212df66910013.tar.xz
mana-0432de0928fbd41d6519a39e2e7212df66910013.zip
Random hacking cleanups in the LocalPlayer class
- Renamed mLastTarget to mLastTargetTime, and mLastAction to mLastActionTime to clarify their use. - NULL -> 0. - Removed the unused mLocalWalkTime member. + Change requested by bjorn. Reviewed-by: Thorjørn Lindeijer
Diffstat (limited to 'src')
-rw-r--r--src/localplayer.cpp62
-rw-r--r--src/localplayer.h18
-rw-r--r--src/net/tmwa/inventoryhandler.cpp4
3 files changed, 35 insertions, 49 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 10081910..212b896d 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -58,22 +58,21 @@
#include <cassert>
-#define AWAY_LIMIT_TIMER 60
+const int AWAY_LIMIT_TIMER = 60;
-LocalPlayer *local_player = NULL;
+LocalPlayer *local_player = 0;
LocalPlayer::LocalPlayer(int id, int subtype):
Being(id, PLAYER, subtype, 0),
- mAttackRange(ATTACK_RANGE_NOT_SET),
+ mAttackRange(-1),
mTargetTime(-1),
- mLastTarget(-1),
- mTarget(NULL),
- mPickUpTarget(NULL),
+ mLastTargetTime(-1),
+ mTarget(0),
+ mPickUpTarget(0),
mGoingToTarget(false), mKeepAttacking(false),
- mLastAction(-1),
+ mLastActionTime(-1),
mWalkingDir(0),
mPathSetByMouse(false),
- mLocalWalkTime(-1),
mMessageTime(0),
mShowIp(false),
mAwayDialog(0),
@@ -101,8 +100,8 @@ LocalPlayer::~LocalPlayer()
void LocalPlayer::logic()
{
// Actions are allowed at 5.5 per second
- if (get_elapsed_time(mLastAction) >= 182)
- mLastAction = -1;
+ if (get_elapsed_time(mLastActionTime) >= 182)
+ mLastActionTime = -1;
// Show XP messages
if (!mMessages.empty())
@@ -127,8 +126,8 @@ void LocalPlayer::logic()
PlayerInfo::logic();
// Targeting allowed 4 times a second
- if (get_elapsed_time(mLastTarget) >= 250)
- mLastTarget = -1;
+ if (get_elapsed_time(mLastTargetTime) >= 250)
+ mLastTargetTime = -1;
if (mTarget)
{
@@ -164,8 +163,8 @@ void LocalPlayer::setAction(Action action, int attackId)
{
if (action == DEAD)
{
- mLastTarget = -1;
- setTarget(NULL);
+ mLastTargetTime = -1;
+ setTarget(0);
}
Being::setAction(action, attackId);
@@ -566,11 +565,8 @@ void LocalPlayer::nextTile(unsigned char dir = 0)
bool LocalPlayer::checkInviteRights(const std::string &guildName)
{
- Guild *guild = getGuild(guildName);
- if (guild)
- {
+ if (Guild *guild = getGuild(guildName))
return guild->getInviteRights();
- }
return false;
}
@@ -626,11 +622,11 @@ Being *LocalPlayer::getTarget() const
void LocalPlayer::setTarget(Being *target)
{
- if ((mLastTarget != -1 || target == this) && target)
+ if ((mLastTargetTime != -1 || target == this) && target)
return;
if (target)
- mLastTarget = tick_time;
+ mLastTargetTime = tick_time;
if (target == mTarget)
return;
@@ -732,7 +728,6 @@ void LocalPlayer::setWalkingDir(int dir)
else if (!dir)
return;
- mLocalWalkTime = tick_time;
mWalkingDir = dir;
// If we're not already walking, start walking.
@@ -782,7 +777,6 @@ void LocalPlayer::stopWalking(bool sendToServer)
if (mAction == MOVE && mWalkingDir)
{
mWalkingDir = 0;
- mLocalWalkTime = 0;
setDestination((int) getPosition().x, (int) getPosition().y);
if (sendToServer)
@@ -799,9 +793,9 @@ void LocalPlayer::stopWalking(bool sendToServer)
void LocalPlayer::toggleSit()
{
- if (mLastAction != -1)
+ if (mLastActionTime != -1)
return;
- mLastAction = tick_time;
+ mLastActionTime = tick_time;
Being::Action newAction;
switch (mAction)
@@ -816,16 +810,16 @@ void LocalPlayer::toggleSit()
void LocalPlayer::emote(Uint8 emotion)
{
- if (mLastAction != -1)
+ if (mLastActionTime != -1)
return;
- mLastAction = tick_time;
+ mLastActionTime = tick_time;
Net::getPlayerHandler()->emote(emotion);
}
void LocalPlayer::attack(Being *target, bool keep)
{
- if (mLastAction != -1)
+ if (mLastActionTime != -1)
return;
// Can only attack when standing still
@@ -846,7 +840,7 @@ void LocalPlayer::attack(Being *target, bool keep)
if (mTarget != target || !mTarget)
{
- mLastTarget = -1;
+ mLastTargetTime = -1;
setTarget(target);
}
@@ -870,7 +864,7 @@ void LocalPlayer::attack(Being *target, bool keep)
setDirection(LEFT);
}
- mLastAction = tick_time;
+ mLastActionTime = tick_time;
setAction(ATTACK);
@@ -894,9 +888,9 @@ void LocalPlayer::stopAttack()
{
if (mAction == ATTACK)
setAction(STAND);
- setTarget(NULL);
+ setTarget(0);
}
- mLastTarget = -1;
+ mLastTargetTime = -1;
}
void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount,
@@ -953,7 +947,7 @@ void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount,
void LocalPlayer::setAttackRange(int range)
{
// When the range is more than the minimal, we accept it
- if (range > ATTACK_RANGE_NOT_SET)
+ if (range > -1)
{
mAttackRange = range;
}
@@ -964,7 +958,7 @@ void LocalPlayer::setAttackRange(int range)
if (weapon)
{
const ItemInfo info = weapon->getInfo();
- if (info.getAttackRange() > ATTACK_RANGE_NOT_SET)
+ if (info.getAttackRange() > -1)
mAttackRange = info.getAttackRange();
}
}
@@ -983,7 +977,7 @@ bool LocalPlayer::withinAttackRange(Being *target)
void LocalPlayer::setGotoTarget(Being *target)
{
- mLastTarget = -1;
+ mLastTargetTime = -1;
mTarget = target;
mGoingToTarget = true;
diff --git a/src/localplayer.h b/src/localplayer.h
index ea429b18..9e2139c2 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -59,12 +59,6 @@ enum
};
/**
- * Attack range not set value
- */
-enum { ATTACK_RANGE_NOT_SET = -1 };
-
-
-/**
* The local player character.
*/
class LocalPlayer : public Being
@@ -231,8 +225,9 @@ class LocalPlayer : public Being
int mAttackRange;
- int mTargetTime; /** How long the being has been targeted **/
- int mLastTarget; /** Time stamp of last targeting action, -1 if none. */
+ int mTargetTime; /**< How long the being has been targeted **/
+ /** Time stamp of last targeting action, -1 if none. */
+ int mLastTargetTime;
int mGMLevel;
@@ -241,14 +236,11 @@ class LocalPlayer : public Being
FloorItem *mPickUpTarget;
bool mGoingToTarget;
- bool mKeepAttacking; /** Whether or not to continue to attack */
- int mLastAction; /**< Time stamp of the last action, -1 if none. */
+ bool mKeepAttacking; /**< Whether or not to continue to attack */
+ int mLastActionTime; /**< Time stamp of the last action, -1 if none. */
int mWalkingDir; /**< The direction the player is walking in. */
bool mPathSetByMouse; /**< Tells if the path was set using mouse */
- int mLocalWalkTime; /**< Timestamp used to control keyboard walk
- messages flooding */
-
typedef std::pair<std::string, int> MessagePair;
/** Queued messages*/
std::list<MessagePair> mMessages;
diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp
index a4f06003..dd74a625 100644
--- a/src/net/tmwa/inventoryhandler.cpp
+++ b/src/net/tmwa/inventoryhandler.cpp
@@ -420,7 +420,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
{
mEquips.setEquipment(getSlot(equipType), -1);
// Reset the attack range to unarmed.
- local_player->setAttackRange(ATTACK_RANGE_NOT_SET);
+ local_player->setAttackRange(-1);
}
break;
@@ -437,7 +437,7 @@ void InventoryHandler::handleMessage(Net::MessageIn &msg)
{
logger->log("Couldn't set attacke range due to the lack"
"of an initialized map.");
- local_player->setAttackRange(ATTACK_RANGE_NOT_SET);
+ local_player->setAttackRange(-1);
}
}
break;