summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Makefile.am1
-rw-r--r--src/being/being.cpp135
-rw-r--r--src/being/being.h7
-rw-r--r--src/enums/being/badgeindex.h40
-rw-r--r--src/enums/simpletypes/enumdefines.h10
6 files changed, 106 insertions, 88 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 85629bf12..419a070ad 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -818,6 +818,7 @@ SET(SRCS
enums/being/actortype.h
enums/being/attacktype.h
enums/being/attributes.h
+ enums/being/badgeindex.h
listeners/actorspritelistener.h
listeners/arrowslistener.cpp
listeners/arrowslistener.h
diff --git a/src/Makefile.am b/src/Makefile.am
index fe04346ef..5ba2cd751 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -743,6 +743,7 @@ manaplus_SOURCES += main.cpp \
enums/being/actortype.h \
enums/being/attacktype.h \
enums/being/attributes.h \
+ enums/being/badgeindex.h \
dragdrop.h \
dropshortcut.cpp \
dropshortcut.h \
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 8413916fe..902811206 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -125,6 +125,9 @@ std::list<BeingCacheEntry*> beingInfoCache;
typedef std::map<int, Guild*>::const_iterator GuildsMapCIter;
typedef std::map<int, int>::const_iterator IntMapCIter;
+#define for_each_badges() \
+ for (int f = 0; f < BadgeIndex::BadgeIndexSize; f++)
+
Being::Being(const BeingId id,
const ActorTypeT type,
const BeingTypeId subtype,
@@ -134,11 +137,7 @@ Being::Being(const BeingId id,
mInfo(BeingInfo::unknown),
mEmotionSprite(nullptr),
mAnimationEffect(nullptr),
- mGmBadge(nullptr),
- mGuildBadge(nullptr),
- mNameBadge(nullptr),
- mPartyBadge(nullptr),
- mTeamBadge(nullptr),
+ mBadges(),
mSpriteAction(SpriteAction::STAND),
mName(),
mRaceName(),
@@ -245,6 +244,9 @@ Being::Being(const BeingId id,
mSpriteDraw[f] = 0;
}
+ for_each_badges()
+ mBadges[f] = nullptr;
+
setMap(map);
setSubtype(subtype, 0);
@@ -291,16 +293,14 @@ Being::~Being()
delete [] mSpriteDraw;
mSpriteDraw = nullptr;
+ for_each_badges()
+ delete2(mBadges[f]);
+
delete2(mSpeechBubble);
delete2(mDispName);
delete2(mText);
delete2(mEmotionSprite);
delete2(mAnimationEffect);
- delete2(mGmBadge);
- delete2(mGuildBadge);
- delete2(mNameBadge);
- delete2(mPartyBadge);
- delete2(mTeamBadge);
mBadgesCount = 0;
#ifdef EATHENA_SUPPORT
delete2(mChat);
@@ -991,13 +991,13 @@ void Being::handleSkill(Being *const victim, const int damage,
void Being::showNameBadge(const bool show)
{
- delete2(mNameBadge);
+ delete2(mBadges[BadgeIndex::Name]);
if (show && !mName.empty() && mShowBadges)
{
const std::string badge = BadgesDB::getNameBadge(mName);
if (!badge.empty())
{
- mNameBadge = AnimatedSprite::load(
+ mBadges[BadgeIndex::Name] = AnimatedSprite::load(
paths.getStringValue("badges") + badge);
}
}
@@ -1047,13 +1047,13 @@ void Being::setShowName(const bool doShowName)
void Being::showGuildBadge(const bool show)
{
- delete2(mGuildBadge);
+ delete2(mBadges[BadgeIndex::Guild]);
if (show && !mGuildName.empty() && mShowBadges)
{
const std::string badge = BadgesDB::getGuildBadge(mGuildName);
if (!badge.empty())
{
- mGuildBadge = AnimatedSprite::load(
+ mBadges[BadgeIndex::Guild] = AnimatedSprite::load(
paths.getStringValue("badges") + badge);
}
}
@@ -1432,16 +1432,12 @@ void Being::setAction(const BeingActionT &action, const int attackId)
mEmotionSprite->play(currentAction);
if (mAnimationEffect)
mAnimationEffect->play(currentAction);
- if (mGmBadge)
- mGmBadge->play(currentAction);
- if (mGuildBadge)
- mGuildBadge->play(currentAction);
- if (mNameBadge)
- mNameBadge->play(currentAction);
- if (mPartyBadge)
- mPartyBadge->play(currentAction);
- if (mTeamBadge)
- mTeamBadge->play(currentAction);
+ for_each_badges()
+ {
+ AnimatedSprite *const sprite = mBadges[f];
+ if (sprite)
+ sprite->play(currentAction);
+ }
#ifdef EATHENA_SUPPORT
if (mHorseSprite)
mHorseSprite->play(currentAction);
@@ -1505,16 +1501,14 @@ void Being::setDirection(const uint8_t direction)
mEmotionSprite->setSpriteDirection(dir);
if (mAnimationEffect)
mAnimationEffect->setSpriteDirection(dir);
- if (mGmBadge)
- mGmBadge->setSpriteDirection(dir);
- if (mGuildBadge)
- mGuildBadge->setSpriteDirection(dir);
- if (mNameBadge)
- mNameBadge->setSpriteDirection(dir);
- if (mPartyBadge)
- mPartyBadge->setSpriteDirection(dir);
- if (mTeamBadge)
- mTeamBadge->setSpriteDirection(dir);
+
+ for_each_badges()
+ {
+ AnimatedSprite *const sprite = mBadges[f];
+ if (sprite)
+ sprite->setSpriteDirection(dir);
+ }
+
#ifdef EATHENA_SUPPORT
if (mHorseSprite)
mHorseSprite->setSpriteDirection(dir);
@@ -1619,16 +1613,12 @@ void Being::logic()
if (mAnimationEffect->isTerminated())
delete2(mAnimationEffect)
}
- if (mGmBadge)
- mGmBadge->update(time);
- if (mGuildBadge)
- mGuildBadge->update(time);
- if (mNameBadge)
- mNameBadge->update(time);
- if (mPartyBadge)
- mPartyBadge->update(time);
- if (mTeamBadge)
- mTeamBadge->update(time);
+ for_each_badges()
+ {
+ AnimatedSprite *const sprite = mBadges[f];
+ if (sprite)
+ sprite->update(time);
+ }
int frameCount = static_cast<int>(getFrameCount());
@@ -1956,30 +1946,14 @@ void Being::drawEmotion(Graphics *const graphics,
x = px + 8 - mBadgesCount * 8;
y = py;
}
- if (mTeamBadge)
+ for_each_badges()
{
- mTeamBadge->draw(graphics, x, y);
- x += 16;
- }
- if (mNameBadge)
- {
- mNameBadge->draw(graphics, x, y);
- x += 16;
- }
- if (mGmBadge)
- {
- mGmBadge->draw(graphics, x, y);
- x += 16;
- }
- if (mGuildBadge)
- {
- mGuildBadge->draw(graphics, x, y);
- x += 16;
- }
- if (mPartyBadge)
- {
- mPartyBadge->draw(graphics, x, y);
-// x += 16;
+ AnimatedSprite *const sprite = mBadges[f];
+ if (sprite)
+ {
+ sprite->draw(graphics, x, y);
+ x += 16;
+ }
}
}
if (mEmotionSprite)
@@ -2640,13 +2614,13 @@ void Being::setGender(const GenderT gender)
void Being::showGmBadge(const bool show)
{
- delete2(mGmBadge);
+ delete2(mBadges[BadgeIndex::Gm]);
if (show && mIsGM && mShowBadges)
{
const std::string gmBadge = paths.getStringValue("gmbadge");
if (!gmBadge.empty())
{
- mGmBadge = AnimatedSprite::load(
+ mBadges[BadgeIndex::Gm] = AnimatedSprite::load(
paths.getStringValue("badges") + gmBadge);
}
}
@@ -3887,14 +3861,14 @@ void Being::setTeamId(const uint16_t teamId)
void Being::showTeamBadge(const bool show)
{
- delete2(mTeamBadge);
+ delete2(mBadges[BadgeIndex::Team]);
if (show && mTeamId && mShowBadges)
{
const std::string name = paths.getStringValue("badges") +
paths.getStringValue(strprintf("team%dbadge",
mTeamId));
if (!name.empty())
- mTeamBadge = AnimatedSprite::load(name);
+ mBadges[BadgeIndex::Team] = AnimatedSprite::load(name);
}
updateBadgesCount();
}
@@ -3910,13 +3884,13 @@ void Being::showBadges(const bool show)
void Being::showPartyBadge(const bool show)
{
- delete2(mPartyBadge);
+ delete2(mBadges[BadgeIndex::Party]);
if (show && !mPartyName.empty() && mShowBadges)
{
const std::string badge = BadgesDB::getPartyBadge(mPartyName);
if (!badge.empty())
{
- mPartyBadge = AnimatedSprite::load(
+ mBadges[BadgeIndex::Party] = AnimatedSprite::load(
paths.getStringValue("badges") + badge);
}
}
@@ -3935,16 +3909,11 @@ void Being::setPartyName(const std::string &name)
void Being::updateBadgesCount()
{
mBadgesCount = 0;
- if (mTeamBadge)
- mBadgesCount ++;
- if (mGmBadge)
- mBadgesCount ++;
- if (mGuildBadge)
- mBadgesCount ++;
- if (mNameBadge)
- mBadgesCount ++;
- if (mPartyBadge)
- mBadgesCount ++;
+ for_each_badges()
+ {
+ if (mBadges[f])
+ mBadgesCount ++;
+ }
}
#ifdef EATHENA_SUPPORT
diff --git a/src/being/being.h b/src/being/being.h
index a28565ba7..7defdc9e9 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -23,6 +23,7 @@
#ifndef BEING_BEING_H
#define BEING_BEING_H
+#include "enums/being/badgeindex.h"
#include "enums/being/reachable.h"
#include "enums/gui/usercolorid.h"
@@ -971,11 +972,7 @@ class Being notfinal : public ActorSprite,
BeingInfo *mInfo;
AnimatedSprite *mEmotionSprite;
AnimatedSprite *mAnimationEffect;
- AnimatedSprite *mGmBadge;
- AnimatedSprite *mGuildBadge;
- AnimatedSprite *mNameBadge;
- AnimatedSprite *mPartyBadge;
- AnimatedSprite *mTeamBadge;
+ AnimatedSprite *mBadges[BadgeIndex::BadgeIndexSize];
std::string mSpriteAction;
std::string mName; /**< Name of character */
diff --git a/src/enums/being/badgeindex.h b/src/enums/being/badgeindex.h
new file mode 100644
index 000000000..fefc5adff
--- /dev/null
+++ b/src/enums/being/badgeindex.h
@@ -0,0 +1,40 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2015 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 ENUMS_BEING_BADGEINDEX_H
+#define ENUMS_BEING_BADGEINDEX_H
+
+#include "enums/simpletypes/enumdefines.h"
+
+enum2Start(BadgeIndex)
+{
+ Away = 0,
+ Inactive = 1,
+ Team = 2,
+ Shop = 3,
+ Gm = 4,
+ Guild = 5,
+ Party = 6,
+ Name = 7,
+ BadgeIndexSize,
+}
+enum2End(BadgeIndex);
+
+#endif // ENUMS_BEING_BADGEINDEX_H
diff --git a/src/enums/simpletypes/enumdefines.h b/src/enums/simpletypes/enumdefines.h
index 95ccad764..a9165df89 100644
--- a/src/enums/simpletypes/enumdefines.h
+++ b/src/enums/simpletypes/enumdefines.h
@@ -43,4 +43,14 @@
#endif // ADVGCC
+#define enum2Start(name) \
+ namespace name \
+ { \
+ enum T
+
+#define enum2End(name) \
+ ;\
+ } \
+ typedef name::T name##T
+
#endif // ENUMS_SIMPLETYPES_ENUMDEFINES_H