summaryrefslogtreecommitdiff
path: root/src/being
diff options
context:
space:
mode:
Diffstat (limited to 'src/being')
-rw-r--r--src/being/being.cpp112
-rw-r--r--src/being/being.h26
-rw-r--r--src/being/beingaction.h45
-rw-r--r--src/being/localplayer.cpp79
-rw-r--r--src/being/localplayer.h4
5 files changed, 154 insertions, 112 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 8db08bb68..eb2c4682f 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -34,6 +34,7 @@
#include "text.h"
#include "being/attributes.h"
+#include "being/beingaction.h"
#include "being/beingcacheentry.h"
#include "being/beingspeech.h"
#include "being/playerrelations.h"
@@ -142,7 +143,7 @@ Being::Being(const int id, const Type type, const uint16_t subtype,
mLastAttackX(0),
mLastAttackY(0),
mGender(GENDER_UNSPECIFIED),
- mAction(STAND),
+ mAction(BeingAction::STAND),
mSubType(0xFFFF),
mDirection(BeingDirection::DOWN),
mDirectionDelayed(0),
@@ -383,7 +384,7 @@ void Being::setPath(const Path &path)
if (mPath.empty())
return;
- if (mAction != MOVE && mAction != DEAD)
+ if (mAction != BeingAction::MOVE && mAction != BeingAction::DEAD)
{
nextTile();
mActionTime = tick_time;
@@ -710,7 +711,7 @@ void Being::handleAttack(Being *const victim, const int damage,
return;
if (this != player_node)
- setAction(Being::ATTACK, attackId);
+ setAction(BeingAction::ATTACK, attackId);
mLastAttackX = victim->getTileX();
mLastAttackY = victim->getTileY();
@@ -730,8 +731,11 @@ void Being::handleAttack(Being *const victim, const int damage,
if (dir)
setDirection(dir);
}
- if (damage && victim->mType == PLAYER && victim->mAction == SIT)
- victim->setAction(STAND, 0);
+ if (damage && victim->mType == PLAYER
+ && victim->mAction == BeingAction::SIT)
+ {
+ victim->setAction(BeingAction::STAND, 0);
+ }
if (mType == PLAYER)
{
@@ -760,7 +764,7 @@ void Being::handleSkill(Being *const victim, const int damage,
return;
if (this != player_node)
- setAction(Being::ATTACK, 1);
+ setAction(BeingAction::ATTACK, 1);
const SkillInfo *const skill = skillDialog->getSkill(skillId);
const SkillData *const data = skill
@@ -778,8 +782,11 @@ void Being::handleSkill(Being *const victim, const int damage,
if (dir)
setDirection(dir);
}
- if (damage && victim->mType == PLAYER && victim->mAction == SIT)
- victim->setAction(STAND, 0);
+ if (damage && victim->mType == PLAYER
+ && victim->mAction == BeingAction::SIT)
+ {
+ victim->setAction(BeingAction::STAND, 0);
+ }
if (data)
{
if (damage > 0)
@@ -1111,13 +1118,13 @@ getSpriteAction(Dead, DEAD)
getSpriteAction(Stand, STAND)
getSpriteAction(Spawn, SPAWN)
-void Being::setAction(const Action &action, const int attackId)
+void Being::setAction(const BeingAction::Action &action, const int attackId)
{
std::string currentAction = SpriteAction::INVALID;
switch (action)
{
- case MOVE:
+ case BeingAction::MOVE:
if (mInfo)
{
playSfx(mInfo->getSound(
@@ -1128,7 +1135,7 @@ void Being::setAction(const Action &action, const int attackId)
// Differentiate walk and run with action name,
// while using only the ACTION_MOVE.
break;
- case SIT:
+ case BeingAction::SIT:
currentAction = getSitAction();
if (mInfo)
{
@@ -1140,7 +1147,7 @@ void Being::setAction(const Action &action, const int attackId)
playSfx(mInfo->getSound(event), nullptr, true, mX, mY);
}
break;
- case ATTACK:
+ case BeingAction::ATTACK:
if (mEquippedWeapon)
{
currentAction = getWeaponAttackAction(mEquippedWeapon);
@@ -1181,14 +1188,14 @@ void Being::setAction(const Action &action, const int attackId)
}
}
break;
- case HURT:
+ case BeingAction::HURT:
if (mInfo)
{
playSfx(mInfo->getSound(SOUND_EVENT_HURT),
this, false, mX, mY);
}
break;
- case DEAD:
+ case BeingAction::DEAD:
currentAction = getDeadAction();
if (mInfo)
{
@@ -1197,10 +1204,10 @@ void Being::setAction(const Action &action, const int attackId)
mYDiff = mInfo->getDeadSortOffsetY();
}
break;
- case STAND:
+ case BeingAction::STAND:
currentAction = getStandAction();
break;
- case SPAWN:
+ case BeingAction::SPAWN:
if (mInfo)
{
playSfx(mInfo->getSound(SOUND_EVENT_SPAWN),
@@ -1316,7 +1323,7 @@ void Being::nextTile()
{
if (mPath.empty())
{
- setAction(STAND, 0);
+ setAction(BeingAction::STAND, 0);
return;
}
@@ -1329,7 +1336,7 @@ void Being::nextTile()
if (!mMap || !mMap->getWalk(pos.x, pos.y, getWalkMask()))
{
- setAction(STAND, 0);
+ setAction(BeingAction::STAND, 0);
return;
}
@@ -1345,7 +1352,7 @@ void Being::nextTile()
mY = pos.y;
const uint8_t height = mMap->getHeightOffset(mX, mY);
mOffsetY = height - mOldHeight;
- setAction(MOVE, 0);
+ setAction(BeingAction::MOVE, 0);
}
void Being::logic()
@@ -1374,15 +1381,15 @@ void Being::logic()
switch (mAction)
{
- case STAND:
- case SIT:
- case DEAD:
- case HURT:
- case SPAWN:
+ case BeingAction::STAND:
+ case BeingAction::SIT:
+ case BeingAction::DEAD:
+ case BeingAction::HURT:
+ case BeingAction::SPAWN:
default:
break;
- case MOVE:
+ case BeingAction::MOVE:
{
if (static_cast<float>(get_elapsed_time(
mActionTime)) >= mSpeed)
@@ -1392,7 +1399,7 @@ void Being::logic()
break;
}
- case ATTACK:
+ case BeingAction::ATTACK:
{
if (!mActionTime)
break;
@@ -1411,7 +1418,7 @@ void Being::logic()
}
}
- if (mAction == MOVE)
+ if (mAction == BeingAction::MOVE)
{
const int xOffset = getXOffset();
const int yOffset = getYOffset();
@@ -1502,7 +1509,7 @@ void Being::petLogic()
if (divX >= warpDist || divY >= warpDist)
{
- setAction(Being::STAND, 0);
+ setAction(BeingAction::STAND, 0);
fixPetSpawnPos(dstX, dstY);
setTileCoords(dstX, dstY);
Net::getPetHandler()->spawn(mOwner, mId, dstX, dstY);
@@ -1562,36 +1569,36 @@ void Being::petLogic()
return;
}
}
- if (mOwner->getCurrentAction() != ATTACK)
+ if (mOwner->getCurrentAction() != BeingAction::ATTACK)
{
- if (mAction == ATTACK)
- setAction(STAND, 0);
+ if (mAction == BeingAction::ATTACK)
+ setAction(BeingAction::STAND, 0);
}
else
{
- if (mAction == STAND || mAction == ATTACK)
- setAction(ATTACK, 0);
+ if (mAction == BeingAction::STAND || mAction == BeingAction::ATTACK)
+ setAction(BeingAction::ATTACK, 0);
}
- if (mAction == STAND || mAction == ATTACK)
+ if (mAction == BeingAction::STAND || mAction == BeingAction::ATTACK)
{
int directionType = 0;
switch (mOwner->getCurrentAction())
{
- case STAND:
- case MOVE:
- case HURT:
- case SPAWN:
+ case BeingAction::STAND:
+ case BeingAction::MOVE:
+ case BeingAction::HURT:
+ case BeingAction::SPAWN:
default:
directionType = mInfo->getDirectionType();
break;
- case SIT:
+ case BeingAction::SIT:
directionType = mInfo->getSitDirectionType();
break;
- case DEAD:
+ case BeingAction::DEAD:
directionType = mInfo->getDeadDirectionType();
break;
- case ATTACK:
+ case BeingAction::ATTACK:
directionType = mInfo->getAttackDirectionType();
break;
}
@@ -1706,7 +1713,7 @@ void Being::drawSpeech(const int offsetX, const int offsetY)
int Being::getOffset(const signed char pos, const signed char neg) const
{
// Check whether we're walking in the requested direction
- if (mAction != MOVE || !(mDirection & (pos | neg)))
+ if (mAction != BeingAction::MOVE || !(mDirection & (pos | neg)))
return 0;
int offset = 0;
@@ -2395,7 +2402,10 @@ void Being::drawSpriteAt(Graphics *const graphics,
y + mapTileSize - 6 + mInfo->getHpBarOffsetY(),
2 * 50, 4);
}
- if (mShowOwnHP && mInfo && player_node == this && mAction != DEAD)
+ if (mShowOwnHP
+ && mInfo
+ && player_node == this
+ && mAction != BeingAction::DEAD)
{
drawHpBar(graphics, PlayerInfo::getAttribute(Attributes::MAX_HP),
PlayerInfo::getAttribute(Attributes::HP), 0,
@@ -2524,7 +2534,7 @@ void Being::recalcSpritesOrder()
if (dir < 0 || dir >= 9)
dir = 0;
// hack for allow different logic in dead player
- if (mAction == DEAD)
+ if (mAction == BeingAction::DEAD)
dir = 9;
const unsigned int hairSlot = Net::getCharServerHandler()->hairSprite();
@@ -3185,29 +3195,29 @@ void Being::fixPetSpawnPos(int &dstX, int &dstY) const
int offsetY1;
switch (mOwner->getCurrentAction())
{
- case SIT:
+ case BeingAction::SIT:
offsetX1 = mInfo->getSitOffsetX();
offsetY1 = mInfo->getSitOffsetY();
break;
- case MOVE:
+ case BeingAction::MOVE:
offsetX1 = mInfo->getMoveOffsetX();
offsetY1 = mInfo->getMoveOffsetY();
break;
- case DEAD:
+ case BeingAction::DEAD:
offsetX1 = mInfo->getDeadOffsetX();
offsetY1 = mInfo->getDeadOffsetY();
break;
- case ATTACK:
+ case BeingAction::ATTACK:
offsetX1 = mInfo->getAttackOffsetX();
offsetY1 = mInfo->getAttackOffsetY();
break;
- case SPAWN:
- case HURT:
- case STAND:
+ case BeingAction::SPAWN:
+ case BeingAction::HURT:
+ case BeingAction::STAND:
default:
offsetX1 = mInfo->getTargetOffsetX();
offsetY1 = mInfo->getTargetOffsetY();
diff --git a/src/being/being.h b/src/being/being.h
index aec735215..52a88bd2e 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -29,6 +29,7 @@
#include "listeners/configlistener.h"
+#include "being/beingaction.h"
#include "being/beingdirection.h"
#include "being/beingflag.h"
#include "being/gender.h"
@@ -85,22 +86,6 @@ class Being : public ActorSprite, public ConfigListener
friend class BeingEquipBackend;
friend class LocalPlayer;
- /**
- * Action the being is currently performing
- * WARNING: Has to be in sync with the same enum in the Being class
- * of the server!
- */
- enum Action
- {
- STAND = 0,
- MOVE,
- ATTACK,
- SIT,
- DEAD,
- HURT,
- SPAWN
- };
-
enum AttackType
{
HIT = 0x00,
@@ -469,19 +454,20 @@ class Being : public ActorSprite, public ConfigListener
/**
* Sets the current action.
*/
- virtual void setAction(const Action &action, const int attackType);
+ virtual void setAction(const BeingAction::Action &action,
+ const int attackType);
/**
* Get the being's action currently performed.
*/
- Action getCurrentAction() const A_WARN_UNUSED
+ BeingAction::Action getCurrentAction() const A_WARN_UNUSED
{ return mAction; }
/**
* Returns whether this being is still alive.
*/
bool isAlive() const A_WARN_UNUSED
- { return mAction != DEAD; }
+ { return mAction != BeingAction::DEAD; }
/**
* Returns the current direction.
@@ -968,7 +954,7 @@ class Being : public ActorSprite, public ConfigListener
int mLastAttackX;
int mLastAttackY;
Gender mGender;
- Action mAction; /**< Action the being is performing */
+ BeingAction::Action mAction;
uint16_t mSubType; /**< Subtype (graphical view, basically) */
uint8_t mDirection; /**< Facing direction */
uint8_t mDirectionDelayed; /**< Facing direction */
diff --git a/src/being/beingaction.h b/src/being/beingaction.h
new file mode 100644
index 000000000..a6bc47b28
--- /dev/null
+++ b/src/being/beingaction.h
@@ -0,0 +1,45 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef BEING_BEINGACTION_H
+#define BEING_BEINGACTION_H
+
+namespace BeingAction
+{
+ /**
+ * Action the being is currently performing
+ * WARNING: Has to be in sync with the same enum in the Being class
+ * of the server!
+ */
+ enum Action
+ {
+ STAND = 0,
+ MOVE,
+ ATTACK,
+ SIT,
+ DEAD,
+ HURT,
+ SPAWN
+ };
+} // BeingAction
+
+#endif // BEING_BEINGACTION_H
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp
index 800cd10a8..2774ab86e 100644
--- a/src/being/localplayer.cpp
+++ b/src/being/localplayer.cpp
@@ -250,7 +250,7 @@ void LocalPlayer::logic()
if (mActivityTime == 0 || mLastAction != -1)
mActivityTime = cur_time;
- if ((mAction != MOVE || mNextStep) && !mNavigatePath.empty())
+ if ((mAction != BeingAction::MOVE || mNextStep) && !mNavigatePath.empty())
{
mNextStep = false;
int dist = 5;
@@ -373,9 +373,10 @@ void LocalPlayer::slowLogic()
BLOCK_END("LocalPlayer::slowLogic")
}
-void LocalPlayer::setAction(const Action &action, const int attackType)
+void LocalPlayer::setAction(const BeingAction::Action &action,
+ const int attackType)
{
- if (action == DEAD)
+ if (action == BeingAction::DEAD)
{
if (!mLastHitFrom.empty())
{
@@ -439,7 +440,7 @@ void LocalPlayer::nextTile(unsigned char dir A_UNUSED = 0)
if (mGoingToTarget && mTarget && withinAttackRange(mTarget))
{
- mAction = Being::STAND;
+ mAction = BeingAction::STAND;
attack(mTarget, true);
mGoingToTarget = false;
mPath.clear();
@@ -453,8 +454,8 @@ void LocalPlayer::nextTile(unsigned char dir A_UNUSED = 0)
if (mPath.empty())
{
- if (mNavigatePath.empty() || mAction != MOVE)
- setAction(STAND);
+ if (mNavigatePath.empty() || mAction != BeingAction::MOVE)
+ setAction(BeingAction::STAND);
else
mNextStep = true;
}
@@ -597,7 +598,7 @@ void LocalPlayer::setWalkingDir(const unsigned char dir)
mWalkingDir = dir;
// If we're not already walking, start walking.
- if (mAction != MOVE && dir)
+ if (mAction != BeingAction::MOVE && dir)
startWalking(dir);
}
@@ -609,7 +610,7 @@ void LocalPlayer::startWalking(const unsigned char dir)
return;
mPickUpTarget = nullptr;
- if (mAction == MOVE && !mPath.empty())
+ if (mAction == BeingAction::MOVE && !mPath.empty())
{
// Just finish the current action, otherwise we get out of sync
Being::setDestination(mX, mY);
@@ -656,7 +657,7 @@ void LocalPlayer::startWalking(const unsigned char dir)
void LocalPlayer::stopWalking(const bool sendToServer)
{
- if (mAction == MOVE && mWalkingDir)
+ if (mAction == BeingAction::MOVE && mWalkingDir)
{
mWalkingDir = 0;
mLocalWalkTime = 0;
@@ -670,7 +671,7 @@ void LocalPlayer::stopWalking(const bool sendToServer)
static_cast<int>(getPosition().x),
static_cast<int>(getPosition().y), -1);
}
- setAction(STAND);
+ setAction(BeingAction::STAND);
}
// No path set anymore, so we reset the path by mouse flag
@@ -685,20 +686,20 @@ bool LocalPlayer::toggleSit() const
if (!client->limitPackets(PACKET_SIT))
return false;
- Being::Action newAction;
+ BeingAction::Action newAction;
switch (mAction)
{
- case STAND:
- case SPAWN:
- newAction = SIT;
+ case BeingAction::STAND:
+ case BeingAction::SPAWN:
+ newAction = BeingAction::SIT;
break;
- case SIT:
- newAction = STAND;
+ case BeingAction::SIT:
+ newAction = BeingAction::STAND;
break;
- case MOVE:
- case ATTACK:
- case DEAD:
- case HURT:
+ case BeingAction::MOVE:
+ case BeingAction::ATTACK:
+ case BeingAction::DEAD:
+ case BeingAction::HURT:
default:
return true;
}
@@ -740,7 +741,7 @@ void LocalPlayer::attack(Being *const target, const bool keep,
const int dist_y = target->getTileY() - mY;
// Must be standing or sitting to attack
- if (mAction != STAND && mAction != SIT)
+ if (mAction != BeingAction::STAND && mAction != BeingAction::SIT)
return;
if (abs(dist_y) >= abs(dist_x))
@@ -762,7 +763,7 @@ void LocalPlayer::attack(Being *const target, const bool keep,
if (target->getType() != Being::PLAYER || checAttackPermissions(target))
{
- setAction(ATTACK);
+ setAction(BeingAction::ATTACK);
if (!client->limitPackets(PACKET_ATTACK))
return;
@@ -782,7 +783,7 @@ void LocalPlayer::stopAttack(const bool keepAttack)
if (!client->limitPackets(PACKET_STOPATTACK))
return;
- if (mServerAttack && mAction == ATTACK)
+ if (mServerAttack && mAction == BeingAction::ATTACK)
Net::getPlayerHandler()->stopAttack();
untarget();
@@ -792,8 +793,8 @@ void LocalPlayer::stopAttack(const bool keepAttack)
void LocalPlayer::untarget()
{
- if (mAction == ATTACK)
- setAction(STAND);
+ if (mAction == BeingAction::ATTACK)
+ setAction(BeingAction::STAND);
if (mTarget)
setTarget(nullptr);
@@ -1838,7 +1839,7 @@ void LocalPlayer::crazyMove()
void LocalPlayer::crazyMove1()
{
- if (mAction == MOVE)
+ if (mAction == BeingAction::MOVE)
return;
// if (!client->limitPackets(PACKET_DIRECTION))
@@ -1872,7 +1873,7 @@ void LocalPlayer::crazyMove1()
void LocalPlayer::crazyMove2()
{
- if (mAction == MOVE)
+ if (mAction == BeingAction::MOVE)
return;
// if (!client->limitPackets(PACKET_DIRECTION))
@@ -1910,7 +1911,7 @@ void LocalPlayer::crazyMove2()
void LocalPlayer::crazyMove3()
{
- if (mAction == MOVE)
+ if (mAction == BeingAction::MOVE)
return;
switch (mCrazyMoveState)
@@ -1944,7 +1945,7 @@ void LocalPlayer::crazyMove3()
void LocalPlayer::crazyMove4()
{
- if (mAction == MOVE)
+ if (mAction == BeingAction::MOVE)
return;
switch (mCrazyMoveState)
@@ -1964,7 +1965,7 @@ void LocalPlayer::crazyMove4()
void LocalPlayer::crazyMove5()
{
- if (mAction == MOVE)
+ if (mAction == BeingAction::MOVE)
return;
switch (mCrazyMoveState)
@@ -1984,7 +1985,7 @@ void LocalPlayer::crazyMove5()
void LocalPlayer::crazyMove6()
{
- if (mAction == MOVE)
+ if (mAction == BeingAction::MOVE)
return;
switch (mCrazyMoveState)
@@ -2028,7 +2029,7 @@ void LocalPlayer::crazyMove6()
void LocalPlayer::crazyMove7()
{
- if (mAction == MOVE)
+ if (mAction == BeingAction::MOVE)
return;
switch (mCrazyMoveState)
@@ -2056,7 +2057,7 @@ void LocalPlayer::crazyMove7()
void LocalPlayer::crazyMove8()
{
- if (mAction == MOVE || !mMap)
+ if (mAction == BeingAction::MOVE || !mMap)
return;
int idx = 0;
const int dist = 1;
@@ -2144,7 +2145,7 @@ void LocalPlayer::crazyMove9()
int dx = 0;
int dy = 0;
- if (mAction == MOVE)
+ if (mAction == BeingAction::MOVE)
return;
switch (mCrazyMoveState)
@@ -2165,7 +2166,7 @@ void LocalPlayer::crazyMove9()
mCrazyMoveState = 2;
if (!allowAction())
return;
- Net::getPlayerHandler()->changeAction(SIT);
+ Net::getPlayerHandler()->changeAction(BeingAction::SIT);
break;
case 2:
mCrazyMoveState = 3;
@@ -2182,7 +2183,7 @@ void LocalPlayer::crazyMoveA()
{
const std::string mMoveProgram(config.getStringValue("crazyMoveProgram"));
- if (mAction == MOVE)
+ if (mAction == BeingAction::MOVE)
return;
if (mMoveProgram.empty())
@@ -2651,7 +2652,7 @@ void LocalPlayer::specialMove(const unsigned char direction)
&& mInvertDirection <= 4)
&& !mIsServerBuggy)
{
- if (mAction == MOVE)
+ if (mAction == BeingAction::MOVE)
return;
int max;
@@ -2785,7 +2786,7 @@ void LocalPlayer::setHome()
const std::string key = mMap->getProperty("_realfilename");
Vector pos = mHomes[key];
- if (mAction == SIT)
+ if (mAction == BeingAction::SIT)
{
const std::map<std::string, Vector>::const_iterator
iter = mHomes.find(key);
@@ -3364,7 +3365,7 @@ void LocalPlayer::imitateEmote(const Being *const being,
}
void LocalPlayer::imitateAction(const Being *const being,
- const Being::Action &action)
+ const BeingAction::Action &action)
{
if (!being)
return;
diff --git a/src/being/localplayer.h b/src/being/localplayer.h
index ec789d0d2..4fa3e8328 100644
--- a/src/being/localplayer.h
+++ b/src/being/localplayer.h
@@ -86,7 +86,7 @@ class LocalPlayer final : public Being,
void slowLogic();
- void setAction(const Action &action,
+ void setAction(const BeingAction::Action &action,
const int attackType = 0) override final;
/**
@@ -344,7 +344,7 @@ class LocalPlayer final : public Being,
const unsigned char emote) const;
void imitateAction(const Being *const being,
- const Being::Action &action);
+ const BeingAction::Action &action);
void imitateDirection(const Being *const being,
const unsigned char dir);