summaryrefslogtreecommitdiff
path: root/src/being
diff options
context:
space:
mode:
Diffstat (limited to 'src/being')
-rw-r--r--src/being/actorsprite.cpp2
-rw-r--r--src/being/actorsprite.h17
-rw-r--r--src/being/actortype.h40
-rw-r--r--src/being/being.cpp98
-rw-r--r--src/being/being.h10
-rw-r--r--src/being/localplayer.cpp20
-rw-r--r--src/being/playerrelations.cpp10
7 files changed, 118 insertions, 79 deletions
diff --git a/src/being/actorsprite.cpp b/src/being/actorsprite.cpp
index ece1320f8..eb695a0e2 100644
--- a/src/being/actorsprite.cpp
+++ b/src/being/actorsprite.cpp
@@ -203,7 +203,7 @@ void ActorSprite::updateStatusEffect(const int index, const bool newStatus)
index, newStatus);
if (!effect)
return;
- if (effect->isPoison() && getType() == PLAYER)
+ if (effect->isPoison() && getType() == ActorType::PLAYER)
setPoison(newStatus);
handleStatusEffect(effect, index);
}
diff --git a/src/being/actorsprite.h b/src/being/actorsprite.h
index 42623027d..5b9c438d8 100644
--- a/src/being/actorsprite.h
+++ b/src/being/actorsprite.h
@@ -28,6 +28,7 @@
#include "resources/map/mapconsts.h"
#include "being/actor.h"
+#include "being/actortype.h"
#include "being/compoundsprite.h"
#include "particle/particlecontainer.h"
@@ -44,18 +45,6 @@ class ActorSpriteListener;
class ActorSprite : public CompoundSprite, public Actor
{
public:
- enum Type
- {
- UNKNOWN = 0,
- PLAYER,
- NPC,
- MONSTER,
- FLOOR_ITEM,
- PORTAL,
- PET,
- AVATAR
- };
-
enum TargetCursorSize
{
TC_SMALL = 0,
@@ -87,8 +76,8 @@ public:
/**
* Returns the type of the ActorSprite.
*/
- virtual Type getType() const A_WARN_UNUSED
- { return UNKNOWN; }
+ virtual ActorType::Type getType() const A_WARN_UNUSED
+ { return ActorType::UNKNOWN; }
void draw1(Graphics *const graphics,
const int offsetX,
diff --git a/src/being/actortype.h b/src/being/actortype.h
new file mode 100644
index 000000000..794dae5f2
--- /dev/null
+++ b/src/being/actortype.h
@@ -0,0 +1,40 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 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_ACTORTYPE_H
+#define BEING_ACTORTYPE_H
+
+namespace ActorType
+{
+ enum Type
+ {
+ UNKNOWN = 0,
+ PLAYER,
+ NPC,
+ MONSTER,
+ FLOOR_ITEM,
+ PORTAL,
+ PET,
+ AVATAR
+ };
+}
+
+#endif // BEING_ACTORTYPE_H
diff --git a/src/being/being.cpp b/src/being/being.cpp
index eb2c4682f..a494df61e 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -108,7 +108,9 @@ std::list<BeingCacheEntry*> beingInfoCache;
typedef std::map<int, Guild*>::const_iterator GuildsMapCIter;
typedef std::map<int, int>::const_iterator IntMapCIter;
-Being::Being(const int id, const Type type, const uint16_t subtype,
+Being::Being(const int id,
+ const ActorType::Type type,
+ const uint16_t subtype,
Map *const map) :
ActorSprite(id),
mNextSound(),
@@ -207,16 +209,16 @@ Being::Being(const int id, const Type type, const uint16_t subtype,
setMap(map);
setSubtype(subtype, 0);
- if (mType == PLAYER)
+ if (mType == ActorType::PLAYER)
mShowName = config.getBoolValue("visiblenames");
- else if (mType != NPC)
+ else if (mType != ActorType::NPC)
mGotComment = true;
config.addListener("visiblenames", this);
reReadConfig();
- if (mType == NPC)
+ if (mType == ActorType::NPC)
setShowName(true);
else
setShowName(mShowName);
@@ -271,7 +273,7 @@ void Being::setSubtype(const uint16_t subtype, const uint8_t look)
mSubType = subtype;
mLook = look;
- if (mType == MONSTER)
+ if (mType == ActorType::MONSTER)
{
mInfo = MonsterDB::get(mSubType);
if (mInfo)
@@ -282,7 +284,7 @@ void Being::setSubtype(const uint16_t subtype, const uint8_t look)
mYDiff = mInfo->getSortOffsetY();
}
}
- else if (mType == NPC)
+ else if (mType == ActorType::NPC)
{
mInfo = NPCDB::get(mSubType);
if (mInfo)
@@ -291,13 +293,13 @@ void Being::setSubtype(const uint16_t subtype, const uint8_t look)
mYDiff = mInfo->getSortOffsetY();
}
}
- else if (mType == AVATAR)
+ else if (mType == ActorType::AVATAR)
{
mInfo = AvatarDB::get(mSubType);
if (mInfo)
setupSpriteDisplay(mInfo->getDisplay(), false);
}
- else if (mType == PET)
+ else if (mType == ActorType::PET)
{
mInfo = PETDB::get(mId);
if (mInfo)
@@ -317,7 +319,7 @@ void Being::setSubtype(const uint16_t subtype, const uint8_t look)
}
}
}
- else if (mType == PLAYER)
+ else if (mType == ActorType::PLAYER)
{
int id = -100 - subtype;
@@ -526,7 +528,7 @@ void Being::takeDamage(Being *const attacker, const int amount,
color = &userPalette->getColor(UserPalette::MISS);
}
}
- else if (mType == MONSTER)
+ else if (mType == ActorType::MONSTER)
{
if (attacker == player_node)
{
@@ -539,7 +541,7 @@ void Being::takeDamage(Being *const attacker, const int amount,
UserPalette::HIT_PLAYER_MONSTER);
}
}
- else if (mType == PLAYER && attacker != player_node
+ else if (mType == ActorType::PLAYER && attacker != player_node
&& this == player_node)
{
// here player was attacked by other player. mark him as enemy.
@@ -556,7 +558,7 @@ void Being::takeDamage(Being *const attacker, const int amount,
{
if (this == player_node)
{
- if (attacker->mType == PLAYER || amount)
+ if (attacker->mType == ActorType::PLAYER || amount)
{
chatWindow->battleChatLog(strprintf("%s : Hit you -%d",
attacker->getName().c_str(), amount), BY_OTHER);
@@ -602,12 +604,12 @@ void Being::takeDamage(Being *const attacker, const int amount,
mHP = 0;
}
- if (mType == MONSTER)
+ if (mType == ActorType::MONSTER)
{
updatePercentHP();
updateName();
}
- else if (mType == PLAYER && socialWindow && getName() != "")
+ else if (mType == ActorType::PLAYER && socialWindow && getName() != "")
{
socialWindow->updateAvatar(getName());
}
@@ -646,7 +648,7 @@ int Being::getHitEffect(const Being *const attacker,
{
const ItemInfo *const attackerWeapon
= attacker->getEquippedWeapon();
- if (attackerWeapon && attacker->getType() == PLAYER)
+ if (attackerWeapon && attacker->getType() == ActorType::PLAYER)
{
if (type == MISS)
hitEffectId = attackerWeapon->getMissEffectId();
@@ -655,7 +657,7 @@ int Being::getHitEffect(const Being *const attacker,
else
hitEffectId = attackerWeapon->getCriticalHitEffectId();
}
- else if (attacker->getType() == MONSTER)
+ else if (attacker->getType() == ActorType::MONSTER)
{
const BeingInfo *const info = attacker->getInfo();
if (info)
@@ -716,7 +718,7 @@ void Being::handleAttack(Being *const victim, const int damage,
mLastAttackX = victim->getTileX();
mLastAttackY = victim->getTileY();
- if (mType == PLAYER && mEquippedWeapon)
+ if (mType == ActorType::PLAYER && mEquippedWeapon)
fireMissile(victim, mEquippedWeapon->getMissileParticleFile());
else if (mInfo->getAttack(attackId))
fireMissile(victim, mInfo->getAttack(attackId)->mMissileParticle);
@@ -731,13 +733,13 @@ void Being::handleAttack(Being *const victim, const int damage,
if (dir)
setDirection(dir);
}
- if (damage && victim->mType == PLAYER
+ if (damage && victim->mType == ActorType::PLAYER
&& victim->mAction == BeingAction::SIT)
{
victim->setAction(BeingAction::STAND, 0);
}
- if (mType == PLAYER)
+ if (mType == ActorType::PLAYER)
{
if (mSpriteIDs.size() >= 10)
{
@@ -782,7 +784,7 @@ void Being::handleSkill(Being *const victim, const int damage,
if (dir)
setDirection(dir);
}
- if (damage && victim->mType == PLAYER
+ if (damage && victim->mType == ActorType::PLAYER
&& victim->mAction == BeingAction::SIT)
{
victim->setAction(BeingAction::STAND, 0);
@@ -803,7 +805,7 @@ void Being::handleSkill(Being *const victim, const int damage,
void Being::setName(const std::string &name)
{
- if (mType == NPC)
+ if (mType == ActorType::NPC)
{
mName = name.substr(0, name.find('#', 0));
showName();
@@ -812,7 +814,7 @@ void Being::setName(const std::string &name)
{
mName = name;
- if (mType == PLAYER && getShowName())
+ if (mType == ActorType::PLAYER && getShowName())
showName();
}
}
@@ -1200,7 +1202,7 @@ void Being::setAction(const BeingAction::Action &action, const int attackId)
if (mInfo)
{
playSfx(mInfo->getSound(SOUND_EVENT_DIE), this, false, mX, mY);
- if (mType == MONSTER || mType == NPC)
+ if (mType == ActorType::MONSTER || mType == ActorType::NPC)
mYDiff = mInfo->getDeadSortOffsetY();
}
break;
@@ -1341,10 +1343,15 @@ void Being::nextTile()
}
mActionTime += static_cast<int>(mSpeed / 10);
- if ((mType != PLAYER || mUseDiagonal) && mX != pos.x && mY != pos.y)
+ if ((mType != ActorType::PLAYER || mUseDiagonal)
+ && mX != pos.x && mY != pos.y)
+ {
mSpeed = static_cast<float>(mWalkSpeed.x * 1.4F);
+ }
else
+ {
mSpeed = mWalkSpeed.x;
+ }
if (mX != pos.x || mY != pos.y)
mOldHeight = mMap->getHeightOffset(mX, mY);
@@ -1458,7 +1465,7 @@ void Being::logic()
&& static_cast<int> ((static_cast<float>(get_elapsed_time(mActionTime))
/ mSpeed)) >= frameCount)
{
- if (mType != PLAYER && actorManager)
+ if (mType != ActorType::PLAYER && actorManager)
actorManager->destroy(this);
}
@@ -1759,7 +1766,7 @@ void Being::updateCoords()
offsetY += mInfo->getNameOffsetY();
}
// Monster names show above the sprite instead of below it
- if (mType == MONSTER)
+ if (mType == ActorType::MONSTER)
offsetY += - getHeight() - mDispName->getHeight();
mDispName->adviseXY(offsetX, offsetY, mMoveNames);
@@ -1767,7 +1774,7 @@ void Being::updateCoords()
void Being::optionChanged(const std::string &value)
{
- if (mType == PLAYER && value == "visiblenames")
+ if (mType == ActorType::PLAYER && value == "visiblenames")
setShowName(config.getBoolValue("visiblenames"));
}
@@ -1829,7 +1836,7 @@ void Being::showName()
std::string displayName(mName);
- if (mType != MONSTER && (mShowGender || mShowLevel))
+ if (mType != ActorType::MONSTER && (mShowGender || mShowLevel))
{
displayName.append(" ");
if (mShowLevel && getLevel() != 0)
@@ -1838,7 +1845,7 @@ void Being::showName()
displayName.append(getGenderSign());
}
- if (mType == MONSTER)
+ if (mType == ActorType::MONSTER)
{
if (config.getBoolValue("showMonstersTakedDamage"))
displayName.append(", ").append(toString(getDamageTaken()));
@@ -1846,11 +1853,12 @@ void Being::showName()
Font *font = nullptr;
if (player_node && player_node->getTarget() == this
- && mType != MONSTER)
+ && mType != ActorType::MONSTER)
{
font = boldFont;
}
- else if (mType == PLAYER && !player_relations.isGoodName(this) && gui)
+ else if (mType == ActorType::PLAYER
+ && !player_relations.isGoodName(this) && gui)
{
font = gui->getSecureFont();
}
@@ -1875,12 +1883,12 @@ void Being::updateColors()
{
if (userPalette)
{
- if (mType == MONSTER)
+ if (mType == ActorType::MONSTER)
{
mNameColor = &userPalette->getColor(UserPalette::MONSTER);
mTextColor = &userPalette->getColor(UserPalette::MONSTER);
}
- else if (mType == NPC)
+ else if (mType == ActorType::NPC)
{
mNameColor = &userPalette->getColor(UserPalette::NPC);
mTextColor = &userPalette->getColor(UserPalette::NPC);
@@ -2003,7 +2011,7 @@ void Being::setSprite(const unsigned int slot, const int id,
if (id1)
{
const ItemInfo &info = ItemDB::get(id1);
- if (!isTempSprite && mMap && mType == PLAYER)
+ if (!isTempSprite && mMap && mType == ActorType::PLAYER)
{
const int pet = info.getPet();
if (pet)
@@ -2018,7 +2026,7 @@ void Being::setSprite(const unsigned int slot, const int id,
const std::string &filename = info.getSprite(mGender, mSubType);
AnimatedSprite *equipmentSprite = nullptr;
- if (!isTempSprite && mType == PLAYER)
+ if (!isTempSprite && mType == ActorType::PLAYER)
{
const int pet = info.getPet();
if (pet)
@@ -2189,7 +2197,7 @@ bool Being::updateFromCache()
}
updateAwayEffect();
- if (mType == PLAYER)
+ if (mType == ActorType::PLAYER)
updateColors();
return true;
}
@@ -2371,7 +2379,7 @@ void Being::drawSpriteAt(Graphics *const graphics,
}
}
- if (mHighlightMonsterAttackRange && mType == ActorSprite::MONSTER
+ if (mHighlightMonsterAttackRange && mType == ActorType::MONSTER
&& isAlive())
{
int attackRange;
@@ -2389,7 +2397,7 @@ void Being::drawSpriteAt(Graphics *const graphics,
}
if (mShowMobHP && mInfo && player_node && player_node->getTarget() == this
- && mType == MONSTER)
+ && mType == ActorType::MONSTER)
{
// show hp bar here
int maxHP = mMaxHP;
@@ -2494,7 +2502,7 @@ void Being::setHP(const int hp)
mHP = hp;
if (mMaxHP < mHP)
mMaxHP = mHP;
- if (mType == MONSTER)
+ if (mType == ActorType::MONSTER)
updatePercentHP();
}
@@ -2882,10 +2890,10 @@ std::string Being::loadComment(const std::string &name, const int type)
std::string str;
switch (type)
{
- case PLAYER:
+ case ActorType::PLAYER:
str = client->getUsersDirectory();
break;
- case NPC:
+ case ActorType::NPC:
str = client->getNpcsDirectory();
break;
default:
@@ -2911,10 +2919,10 @@ void Being::saveComment(const std::string &restrict name,
std::string dir;
switch (type)
{
- case PLAYER:
+ case ActorType::PLAYER:
dir = client->getUsersDirectory();
break;
- case NPC:
+ case ActorType::NPC:
dir = client->getNpcsDirectory();
break;
default:
@@ -3098,7 +3106,7 @@ void Being::addPet(const int id)
}
Being *const being = actorManager->createBeing(
- id, ActorSprite::PET, 0);
+ id, ActorType::PET, 0);
if (being)
{
being->setOwner(this);
@@ -3290,7 +3298,7 @@ void Being::playSfx(const SoundInfo &sound, Being *const being,
void Being::setLook(const uint8_t look)
{
- if (mType == PLAYER)
+ if (mType == ActorType::PLAYER)
setSubtype(mSubType, look);
}
diff --git a/src/being/being.h b/src/being/being.h
index 52a88bd2e..dfa920e68 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -111,14 +111,16 @@ class Being : public ActorSprite, public ConfigListener
* @param subtype partly determines the type of the being
* @param map the map the being is on
*/
- Being(const int id, const Type type, const uint16_t subtype,
+ Being(const int id,
+ const ActorType::Type type,
+ const uint16_t subtype,
Map *const map);
A_DELETE_COPY(Being)
virtual ~Being();
- Type getType() const A_WARN_UNUSED
+ ActorType::Type getType() const override final A_WARN_UNUSED
{ return mType; }
/**
@@ -630,7 +632,7 @@ class Being : public ActorSprite, public ConfigListener
void setGM(const bool gm);
bool canTalk() const A_WARN_UNUSED
- { return mType == NPC; }
+ { return mType == ActorType::NPC; }
void talkTo() const;
@@ -981,7 +983,7 @@ class Being : public ActorSprite, public ConfigListener
void dumpSprites() const;
- const Type mType;
+ const ActorType::Type mType;
/** Speech Bubble components */
SpeechBubble *mSpeechBubble;
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp
index 2774ab86e..d22e8503c 100644
--- a/src/being/localplayer.cpp
+++ b/src/being/localplayer.cpp
@@ -101,7 +101,7 @@ extern MiniStatusWindow *miniStatusWindow;
extern SkillDialog *skillDialog;
LocalPlayer::LocalPlayer(const int id, const int subtype) :
- Being(id, PLAYER, subtype, nullptr),
+ Being(id, ActorType::PLAYER, subtype, nullptr),
AttributeListener(),
StatListener(),
mGMLevel(0),
@@ -295,7 +295,7 @@ void LocalPlayer::logic()
if (mTarget)
{
- if (mTarget->getType() == ActorSprite::NPC)
+ if (mTarget->getType() == ActorType::NPC)
{
// NPCs are always in range
mTarget->setTargetType(TCT_IN_RANGE);
@@ -314,7 +314,7 @@ void LocalPlayer::logic()
mTarget->setTargetType(targetType);
if (!mTarget->isAlive() && (!mTargetDeadPlayers
- || mTarget->getType() != Being::PLAYER))
+ || mTarget->getType() != ActorType::PLAYER))
{
stopAttack(true);
}
@@ -532,7 +532,7 @@ void LocalPlayer::setTarget(Being *const target)
oldTarget = mTarget;
}
- if (mTarget && mTarget->getType() == ActorSprite::MONSTER)
+ if (mTarget && mTarget->getType() == ActorType::MONSTER)
mTarget->setShowName(false);
mTarget = target;
@@ -547,7 +547,7 @@ void LocalPlayer::setTarget(Being *const target)
mTarget->updateName();
}
- if (target && target->getType() == ActorSprite::MONSTER)
+ if (target && target->getType() == ActorType::MONSTER)
target->setShowName(true);
}
@@ -731,7 +731,7 @@ void LocalPlayer::attack(Being *const target, const bool keep,
{
mKeepAttacking = keep;
- if (!target || target->getType() == ActorSprite::NPC)
+ if (!target || target->getType() == ActorType::NPC)
return;
if (mTarget != target)
@@ -761,7 +761,7 @@ void LocalPlayer::attack(Being *const target, const bool keep,
mActionTime = tick_time;
- if (target->getType() != Being::PLAYER || checAttackPermissions(target))
+ if (target->getType() != ActorType::PLAYER || checAttackPermissions(target))
{
setAction(BeingAction::ATTACK);
@@ -3297,7 +3297,7 @@ void LocalPlayer::attack2(Being *const target, const bool keep,
return;
}
setTarget(target);
- if (target->getType() != Being::NPC)
+ if (target->getType() != ActorType::NPC)
{
mKeepAttacking = true;
moveToTarget();
@@ -3510,7 +3510,7 @@ void LocalPlayer::followMoveTo(const Being *const being,
if (actorManager)
{
Being *const b = actorManager->findBeingByName(
- mPlayerFollowed, Being::PLAYER);
+ mPlayerFollowed, ActorType::PLAYER);
setTarget(b);
}
}
@@ -3665,7 +3665,7 @@ void LocalPlayer::checkNewName(Being *const being)
return;
const std::string &nick = being->getName();
- if (being->getType() == ActorSprite::PLAYER)
+ if (being->getType() == ActorType::PLAYER)
{
const Guild *const guild = getGuild();
if (guild)
diff --git a/src/being/playerrelations.cpp b/src/being/playerrelations.cpp
index cdba9bfb6..486713434 100644
--- a/src/being/playerrelations.cpp
+++ b/src/being/playerrelations.cpp
@@ -249,9 +249,9 @@ void PlayerRelationsManager::signalUpdate(const std::string &name)
if (actorManager)
{
Being *const being = actorManager->findBeingByName(
- name, Being::PLAYER);
+ name, ActorType::PLAYER);
- if (being && being->getType() == Being::PLAYER)
+ if (being && being->getType() == ActorType::PLAYER)
being->updateColors();
}
}
@@ -300,7 +300,7 @@ bool PlayerRelationsManager::hasPermission(const Being *const being,
if (!being)
return false;
- if (being->getType() == ActorSprite::PLAYER)
+ if (being->getType() == ActorType::PLAYER)
return hasPermission(being->getName(), flags) == flags;
return true;
}
@@ -321,9 +321,9 @@ bool PlayerRelationsManager::hasPermission(const std::string &name,
if (mIgnoreStrategy)
{
Being *const b = actorManager->findBeingByName(
- name, ActorSprite::PLAYER);
+ name, ActorType::PLAYER);
- if (b && b->getType() == ActorSprite::PLAYER)
+ if (b && b->getType() == ActorType::PLAYER)
mIgnoreStrategy->ignore(b, rejections);
}
}