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

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