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