GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/resources/skill/skillinfo.cpp Lines: 0 66 0.0 %
Date: 2017-11-29 Branches: 0 54 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2004-2009  The Mana World Development Team
4
 *  Copyright (C) 2009-2010  The Mana Developers
5
 *  Copyright (C) 2011-2017  The ManaPlus Developers
6
 *
7
 *  This file is part of The ManaPlus Client.
8
 *
9
 *  This program is free software; you can redistribute it and/or modify
10
 *  it under the terms of the GNU General Public License as published by
11
 *  the Free Software Foundation; either version 2 of the License, or
12
 *  any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
#include "resources/skill/skillinfo.h"
24
25
#include "being/playerinfo.h"
26
27
#include "gui/models/skillmodel.h"
28
29
#include "utils/foreach.h"
30
#include "utils/stringutils.h"
31
32
#include "resources/skill/skilldata.h"
33
#include "resources/skill/skilltypelist.h"
34
35
#include "debug.h"
36
37
SkillInfo::SkillInfo() :
38
    skillLevel(),
39
    skillEffect(),
40
    useButton(),
41
    errorText(),
42
    castingAction(),
43
    castingRideAction(),
44
    castingSkyAction(),
45
    castingWaterAction(),
46
    dataMap(),
47
    model(nullptr),
48
    tab(nullptr),
49
    data(nullptr),
50
    level(0),
51
    customSelectedLevel(0),
52
    customOffsetX(0),
53
    customOffsetY(0),
54
    skillLevelWidth(0),
55
    id(0),
56
    range(0),
57
    sp(0),
58
    duration(0),
59
    durationTime(0),
60
    cooldown(0),
61
    x(0),
62
    y(0),
63
    type(SkillType::Unknown),
64
    owner(SkillOwner::Player),
65
    customCastType(CastType::Default),
66
    modifiable(Modifiable_false),
67
    visible(Visible_false),
68
    alwaysVisible(Visible_false),
69
    useTextParameter(false)
70
{
71
    dataMap[0] = new SkillData;
72
    data = dataMap[0];
73
}
74
75
SkillInfo::~SkillInfo()
76
{
77
    FOR_EACH (SkillDataMapIter, it, dataMap)
78
        delete (*it).second;
79
    dataMap.clear();
80
}
81
82
void SkillInfo::update()
83
{
84
    const int baseLevel = PlayerInfo::getSkillLevel(id);
85
    if (modifiable == Modifiable_false && baseLevel == 0)
86
    {
87
        if (visible == Visible_true)
88
        {
89
            visible = Visible_false;
90
            if (model != nullptr)
91
                model->updateVisibilities();
92
        }
93
        return;
94
    }
95
96
    const bool updateVisibility = (visible == Visible_false);
97
    visible = Visible_true;
98
99
    if (baseLevel == 0)
100
    {
101
        skillLevel.clear();
102
    }
103
    else
104
    {
105
        if (customSelectedLevel == 0)
106
        {
107
            // TRANSLATORS: skill level
108
            skillLevel = strprintf(_("Lvl: %d"), baseLevel);
109
        }
110
        else
111
        {
112
            // TRANSLATORS: skill level
113
            skillLevel = strprintf(_("Lvl: %d / %d"),
114
                customSelectedLevel,
115
                baseLevel);
116
        }
117
    }
118
119
    // TRANSLATORS: skill type
120
    const char *const typeStr = _("Type: %s");
121
122
    if (type == SkillType::Unknown)
123
    {
124
        // TRANSLATORS: Skill type
125
        skillEffect = strprintf(typeStr, _("Unknown"));
126
    }
127
    else
128
    {
129
        skillEffect.clear();
130
        for (size_t f = 0; f < skillTypeListSize; f ++)
131
        {
132
            const SkillTypeEntry &item = skillTypeList[f];
133
            if ((item.type & type) != 0)
134
            {
135
                if (!skillEffect.empty())
136
                    skillEffect.append(", ");
137
                skillEffect.append(strprintf(typeStr, item.name));
138
            }
139
        }
140
    }
141
    if (skillEffect.empty())
142
    {
143
        // TRANSLATORS: Skill type
144
        skillEffect = strprintf(typeStr, _("Unknown:"));
145
        skillEffect.append(" ").append(toString(CAST_S32(type)));
146
    }
147
148
    if (sp != 0)
149
    {
150
        // TRANSLATORS: skill mana
151
        skillEffect.append(strprintf(_(" / Mana: -%d"), sp));
152
    }
153
154
    if (range > 0)
155
    {
156
        if (!skillEffect.empty())
157
            skillEffect.append(" / ");
158
        // TRANSLATORS: skill range
159
        skillEffect.append(strprintf(_("Range: %d"), range));
160
    }
161
162
    level = baseLevel;
163
    if (customSelectedLevel > level)
164
        customSelectedLevel = level;
165
166
    skillLevelWidth = -1;
167
168
    if (updateVisibility && (model != nullptr))
169
        model->updateVisibilities();
170
171
    data = getData(level);
172
    if (data == nullptr)
173
        data = dataMap[0];
174
}
175
176
177
void SkillInfo::addData(const int level1, SkillData *const data1)
178
{
179
    dataMap[level1] = data1;
180
}
181
182
SkillData *SkillInfo::getData(const int level1) const
183
{
184
    const SkillDataMapCIter it = dataMap.find(level1);
185
    if (it == dataMap.end())
186
        return nullptr;
187
    return (*it).second;
188
}
189
190
SkillData *SkillInfo::getData1(const int lev) const
191
{
192
    const SkillDataMapCIter it = dataMap.find(lev);
193
    if (it == dataMap.end())
194
        return (*dataMap.begin()).second;
195
    return (*it).second;
196
}
197
198
std::string SkillInfo::toDataStr() const
199
{
200
    return strprintf("%d %d %d",
201
        CAST_S32(customCastType),
202
        customOffsetX,
203
        customOffsetY);
204
}