summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-07-24 20:41:46 +0300
committerAndrei Karas <akaras@inbox.ru>2016-07-24 20:58:46 +0300
commit3cdb0d5516f5234dcebb118a26e405074de701f8 (patch)
treede5cd8f80bc1b762245a78e082676f630447d49b
parentbeca7c9c25815339244c6f2542054d25c59089b5 (diff)
downloadmanaverse-3cdb0d5516f5234dcebb118a26e405074de701f8.tar.gz
manaverse-3cdb0d5516f5234dcebb118a26e405074de701f8.tar.bz2
manaverse-3cdb0d5516f5234dcebb118a26e405074de701f8.tar.xz
manaverse-3cdb0d5516f5234dcebb118a26e405074de701f8.zip
Add castingeffect object for draw casting effect in specified position and sorting.
Now casting effect drawed on ground and not over players or mobs.
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/being/being.cpp73
-rw-r--r--src/being/being.h9
-rw-r--r--src/being/castingeffect.cpp101
-rw-r--r--src/being/castingeffect.h81
6 files changed, 202 insertions, 66 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 56209c3c7..67d3a0f44 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -940,6 +940,8 @@ SET(SRCS
enums/being/beingdirection.h
being/beingflag.h
being/beingspeech.h
+ being/castingeffect.cpp
+ being/castingeffect.h
beingequipbackend.cpp
beingequipbackend.h
spellmanager.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index db7750854..8d4aa8b16 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -845,6 +845,8 @@ manaplus_SOURCES += main.cpp \
enums/being/beingdirection.h \
being/beingflag.h \
being/beingspeech.h \
+ being/castingeffect.cpp \
+ being/castingeffect.h \
being/localplayer.cpp \
being/localplayer.h \
being/mercenaryinfo.h \
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 75a18b2f2..04dc00025 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -36,6 +36,7 @@
#include "being/beingcacheentry.h"
#include "being/beingflag.h"
#include "being/beingspeech.h"
+#include "being/castingeffect.h"
#include "being/localplayer.h"
#include "being/playerinfo.h"
#include "being/playerrelations.h"
@@ -245,11 +246,6 @@ Being::Being(const BeingId id,
mManner(0),
mAreaSize(11),
mCastEndTime(0),
- mCastRectX(0),
- mCastRectSize(0),
- mCastRectY(0),
- mCastAnimationX(0),
- mCastAnimationY(0),
#ifdef EATHENA_SUPPORT
mCreatorId(BeingId_zero),
#endif
@@ -265,8 +261,7 @@ Being::Being(const BeingId id,
mAway(false),
mInactive(false),
mNeedPosUpdate(true),
- mPetAi(true),
- mDrawCast(false)
+ mPetAi(true)
{
for (int f = 0; f < 20; f ++)
{
@@ -1631,8 +1626,6 @@ void Being::setAction(const BeingActionT &restrict action,
mEmotionSprite->play(currentAction);
if (mAnimationEffect)
mAnimationEffect->play(currentAction);
- if (mCastingEffect)
- mCastingEffect->play(currentAction);
for_each_badges()
{
AnimatedSprite *const sprite = mBadges[f];
@@ -1704,8 +1697,6 @@ void Being::setDirection(const uint8_t direction) restrict2
mEmotionSprite->setSpriteDirection(dir);
if (mAnimationEffect)
mAnimationEffect->setSpriteDirection(dir);
- if (mCastingEffect)
- mCastingEffect->setSpriteDirection(dir);
for_each_badges()
{
@@ -1835,7 +1826,6 @@ void Being::logic() restrict2
if (mCastEndTime != 0 && mCastEndTime < tick_time)
{
mCastEndTime = 0;
- mDrawCast = false;
delete2(mCastingEffect);
}
@@ -3548,29 +3538,6 @@ void Being::drawPlayer(Graphics *restrict const graphics,
drawBeingCursor(graphics, px, py);
drawPlayerSpriteAt(graphics, px, py);
#endif
- if (mDrawCast)
- drawCasting(graphics, offsetX, offsetY);
- }
-}
-
-void Being::drawCasting(Graphics *const graphics,
- const int offsetX,
- const int offsetY) const
-{
- graphics->setColor(userPalette->getColorWithAlpha(
- UserColorId::ATTACK_RANGE_BORDER));
-
- graphics->drawRectangle(Rect(
- mCastRectX + offsetX,
- mCastRectY + offsetY,
- mCastRectSize,
- mCastRectSize));
-
- if (mCastingEffect)
- {
- mCastingEffect->draw(graphics,
- mCastAnimationX + offsetX,
- mCastAnimationY + offsetY);
}
}
@@ -5097,14 +5064,9 @@ void Being::addCast(const int dstX,
if (waitTimeTicks <= 0)
{
mCastEndTime = 0;
- mDrawCast = false;
return;
}
mCastEndTime = tick_time + waitTimeTicks;
- mDrawCast = true;
- mCastRectX = (dstX - range) * mapTileSize;
- mCastRectY = (dstY - range) * mapTileSize;
- mCastRectSize = range * mapTileSize * 2 + mapTileSize;
SkillData *const data = skillDialog->getSkillDataByLevel(
skillId,
skillLevel);
@@ -5112,25 +5074,18 @@ void Being::addCast(const int dstX,
if (data)
{
const std::string castingAnimation = data->castingAnimation;
- if (!castingAnimation.empty())
- {
- mCastingEffect = AnimatedSprite::load(
- paths.getStringValue("sprites") + castingAnimation);
- if (mCastingEffect)
- {
- mCastAnimationX = mCastRectX +
- (mCastRectSize - mCastingEffect->getWidth()) / 2;
- mCastAnimationY = mCastRectY +
- (mCastRectSize - mCastingEffect->getHeight()) / 2;
- }
- else
- {
- reportAlways("Skill %d/%d casting animation '%s' load failed",
- skillId,
- skillLevel,
- castingAnimation.c_str());
- }
- }
+ mCastingEffect = new CastingEffect(skillId,
+ skillLevel,
+ castingAnimation,
+ dstX,
+ dstY,
+ range);
+ mCastingEffect->setMap(mMap);
+ }
+ else
+ {
+ reportAlways("Want to draw casting for unknown skill %d",
+ skillId);
}
}
diff --git a/src/being/being.h b/src/being/being.h
index 72e6d2065..737a5efd5 100644
--- a/src/being/being.h
+++ b/src/being/being.h
@@ -50,6 +50,7 @@ static const int DEFAULT_BEING_HEIGHT = 32;
class AnimatedSprite;
class BeingCacheEntry;
+class CastingEffect;
class Color;
class Equipment;
class FlashText;
@@ -1095,7 +1096,7 @@ class Being notfinal : public ActorSprite,
BeingInfo *restrict mInfo;
AnimatedSprite *restrict mEmotionSprite;
AnimatedSprite *restrict mAnimationEffect;
- AnimatedSprite *restrict mCastingEffect;
+ CastingEffect *restrict mCastingEffect;
AnimatedSprite *restrict mBadges[BadgeIndex::BadgeIndexSize];
std::string mSpriteAction;
@@ -1272,11 +1273,6 @@ class Being notfinal : public ActorSprite,
int mManner;
int mAreaSize;
int mCastEndTime;
- int mCastRectX;
- int mCastRectSize;
- int mCastRectY;
- int mCastAnimationX;
- int mCastAnimationY;
#ifdef EATHENA_SUPPORT
BeingId mCreatorId;
#endif
@@ -1293,7 +1289,6 @@ class Being notfinal : public ActorSprite,
bool mInactive;
bool mNeedPosUpdate;
bool mPetAi;
- bool mDrawCast;
};
extern std::list<BeingCacheEntry*> beingInfoCache;
diff --git a/src/being/castingeffect.cpp b/src/being/castingeffect.cpp
new file mode 100644
index 000000000..abacfde48
--- /dev/null
+++ b/src/being/castingeffect.cpp
@@ -0,0 +1,101 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2016 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/>.
+ */
+
+#include "being/castingeffect.h"
+
+#include "configuration.h"
+
+#include "const/resources/map/map.h"
+
+#include "gui/userpalette.h"
+
+#include "render/graphics.h"
+
+#include "resources/sprite/animatedsprite.h"
+
+#include "utils/checkutils.h"
+
+#include "debug.h"
+
+CastingEffect::CastingEffect(const int skillId,
+ const int skillLevel,
+ const std::string &animation,
+ const int x,
+ const int y,
+ const int range) :
+ Actor(),
+ mSprite(animation.empty() ? nullptr :
+ AnimatedSprite::load(paths.getStringValue("sprites") + animation)),
+ mPixelX(x * mapTileSize),
+ mPixelY(y * mapTileSize),
+ mRectX((x - range) * mapTileSize),
+ mRectY((y - range) * mapTileSize),
+ mRectSize(range * mapTileSize * 2 + mapTileSize),
+ mAnimationX(mRectX + (mRectSize - (mSprite ?
+ mSprite->getWidth() : 0)) / 2),
+ mAnimationY(mRectY + (mRectSize - (mSprite ?
+ mSprite->getHeight() : 0)) / 2),
+ mYDiff(range * mapTileSize + 31)
+{
+ if (!mSprite)
+ {
+ reportAlways("Skill %d/%d casting animation '%s' load failed",
+ skillId,
+ skillLevel,
+ animation.c_str());
+ }
+}
+
+CastingEffect::~CastingEffect()
+{
+}
+
+void CastingEffect::draw(Graphics *const graphics,
+ const int offsetX,
+ const int offsetY) const
+{
+ graphics->setColor(userPalette->getColorWithAlpha(
+ UserColorId::ATTACK_RANGE_BORDER));
+
+ graphics->drawRectangle(Rect(
+ mRectX + offsetX,
+ mRectY + offsetY,
+ mRectSize,
+ mRectSize));
+ if (mSprite)
+ {
+ mSprite->draw(graphics,
+ mAnimationX + offsetX,
+ mAnimationY + offsetY);
+ }
+}
+
+void CastingEffect::update(const int time)
+{
+ if (mSprite)
+ mSprite->update(time);
+}
+
+bool CastingEffect::isTerminated() const
+{
+ if (mSprite)
+ return mSprite->isTerminated();
+ return false;
+}
diff --git a/src/being/castingeffect.h b/src/being/castingeffect.h
new file mode 100644
index 000000000..c12305b47
--- /dev/null
+++ b/src/being/castingeffect.h
@@ -0,0 +1,81 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2016 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_CASTINGEFFECT_H
+#define BEING_CASTINGEFFECT_H
+
+#include "being/actor.h"
+
+#include "enums/being/actortype.h"
+
+#include "enums/simpletypes/beingid.h"
+
+#include "localconsts.h"
+
+class AnimatedSprite;
+class Map;
+
+class CastingEffect final : public Actor
+{
+ public:
+ CastingEffect(const int skillId,
+ const int skillLevel,
+ const std::string &animation,
+ const int x,
+ const int y,
+ const int range);
+
+ A_DELETE_COPY(CastingEffect)
+
+ virtual ~CastingEffect();
+
+ virtual ActorTypeT getType() const noexcept2 A_WARN_UNUSED
+ { return ActorType::Unknown; }
+
+ void draw(Graphics *const graphics,
+ const int offsetX,
+ const int offsetY) const override final A_NONNULL(2);
+
+ virtual int getSortPixelY() const restrict2 override A_WARN_UNUSED
+ { return mPixelY - mYDiff; }
+
+ void update(const int time);
+
+ bool isTerminated() const;
+
+ float getAlpha() const override final A_WARN_UNUSED
+ { return 1.0f; }
+
+ void setAlpha(const float alpha A_UNUSED) override final
+ { }
+
+ protected:
+ AnimatedSprite *mSprite;
+ int mPixelX;
+ int mPixelY;
+ int mRectX;
+ int mRectY;
+ int mRectSize;
+ int mAnimationX;
+ int mAnimationY;
+ int mYDiff;
+};
+
+#endif // BEING_CASTINGEFFECT_H