GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/being/castingeffect.cpp Lines: 1 37 2.7 %
Date: 2017-11-29 Branches: 0 48 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2017  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "being/castingeffect.h"
22
23
#include "configuration.h"
24
25
#include "const/resources/map/map.h"
26
27
#include "gui/userpalette.h"
28
29
#include "render/graphics.h"
30
31
#include "resources/sprite/animatedsprite.h"
32
33
#include "utils/checkutils.h"
34
#include "utils/delete2.h"
35
36
#include "debug.h"
37
38
CastingEffect::CastingEffect(const int skillId,
39
                             const int skillLevel,
40
                             const std::string &animation,
41
                             const int x,
42
                             const int y,
43
                             const int range) :
44
    Actor(),
45
    mSprite(animation.empty() ? nullptr :
46
        AnimatedSprite::load(paths.getStringValue("sprites") + animation)),
47
    mRectX((x - range) * mapTileSize),
48
    mRectY((y - range) * mapTileSize),
49
    mRectSize(range * mapTileSize * 2 + mapTileSize),
50
    mAnimationX(mRectX + (mRectSize - (mSprite != nullptr ?
51
        mSprite->getWidth() : 0)) / 2),
52
    mAnimationY(mRectY + (mRectSize - (mSprite != nullptr ?
53
        mSprite->getHeight() : 0)) / 2)
54
{
55
    mPixelX = x * mapTileSize;
56
    mPixelY = y * mapTileSize;
57
    mYDiff = range * mapTileSize + 31;
58
    if (mSprite == nullptr)
59
    {
60
        reportAlways("Skill %d/%d casting animation '%s' load failed",
61
            skillId,
62
            skillLevel,
63
            animation.c_str());
64
    }
65
}
66
67
CastingEffect::~CastingEffect()
68
{
69
    delete2(mSprite);
70
}
71
72
void CastingEffect::draw(Graphics *const graphics,
73
                         const int offsetX,
74
                         const int offsetY) const
75
{
76
    graphics->setColor(userPalette->getColorWithAlpha(
77
        UserColorId::ATTACK_RANGE_BORDER));
78
79
    graphics->drawRectangle(Rect(
80
        mRectX + offsetX,
81
        mRectY + offsetY,
82
        mRectSize,
83
        mRectSize));
84
    if (mSprite != nullptr)
85
    {
86
        mSprite->drawRescaled(graphics,
87
            mRectX + offsetX,
88
            mRectY + offsetY,
89
            mRectSize,
90
            mRectSize);
91
    }
92
}
93
94
void CastingEffect::update(const int time)
95
{
96
    if (mSprite != nullptr)
97
        mSprite->update(time);
98
}
99
100
bool CastingEffect::isTerminated() const
101
{
102
    if (mSprite != nullptr)
103
        return mSprite->isTerminated();
104
    return false;
105
4
}